Showing posts with label using. Show all posts
Showing posts with label using. Show all posts

Saturday, April 12, 2014

Example of using Notification Builder

,
android.app.Notification.Builder is a builder class for Notification objects. Provides a convenient way to set the various fields of a Notification and generate content views using the platforms notification layout template. If your app supports versions of Android as old as API level 4, you can instead use NotificationCompat.Builder, available in the Android Support library.

Example of using Notification.Builder

Example of using Notification.Builder


package com.example.androidnotificationbuilder;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

private static final int MY_NOTIFICATION_ID=1;
NotificationManager notificationManager;
Notification myNotification;
private final String myBlog = "http://android-er.blogspot.com/";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonSend = (Button)findViewById(R.id.send);
buttonSend.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
Context context = getApplicationContext();
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myBlog));
PendingIntent pendingIntent = PendingIntent.getActivity(
MainActivity.this,
0,
myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);

myNotification = new Notification.Builder(context)
.setContentTitle("Exercise of Notification!")
.setContentText("http://android-er.blogspot.com/")
.setTicker("Notification!")
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.build();

notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);

}});

}

}



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/send"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send a Notification" />

</LinearLayout>


Note: minSdkVersion have to be set ="16".

Read more

Saturday, March 29, 2014

Register your app using YouTube Android Player API and obtain API Key

,
To use YouTube Android Player API in your app, you have to register it and obtain API key. This post show you the steps to do so.

- Login with your Google account in Google APIs Console.

- Pull-down the Slection on left, and click Create... under Other Projects.



- Enter name of your project.



- Enable YouTube Data API v3 to ON.



- And then click to select API Access, and you will found you API key. You have to insert it in your code to use YouTube Android Player API.





To develop Android apps with YouTube Android Player API, read the posts in YouTube Android Player API step-by-step.

Read more
 

Download Android Game Copyright © 2016 -- Powered by Blogger