---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