Saturday, December 9, 2017

Simple Notification for android

---This code will generate simple notification through a button click.--

// build the content of  notification

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setContentTitle("Normal Notification");
builder.setContentText("This a normal notification");
builder.setTicker("This is a ticker");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setAutoCancel(true);

// add notification sound

Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Uri uri1= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
builder.setSound(uri);
// notification through notification manager

Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1234, notification);



No comments:

Post a Comment

Speedup Android Studio

Go to Help ->Edit Custom VM Options, and chnge this 4 setting. After that close your Android Studio. This settings are for 8gb of ram pc...