private void createAndGenerateNotifcation() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this).setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Notification TItile").setContentText("Body"); mBuilder.setAutoCancel(true); try { Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" +
R.raw.yourfile
); mBuilder.setSound(uri); } catch (Exception e) { e.printStackTrace(); } // Intent resultIntent = new Intent(this, Notification.class); Intent resultIntent = new Intent(); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(Notification.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify((int) System.currentTimeMillis(), mBuilder.build()); }
Structure of Notification in Android
- Content title
- Large icon
- Content text
- Content info
- Small icon
- Time that the notification was issued. You can set an explicit value with setWhen(); if you don't it defaults to the time that the system received the notification.
Lets have a look on description
Setting Notification custom sound - Keep your file inside raw folder of res and give URI to notification like this try {
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.yourfile);
mBuilder.setSound(uri);
} catch (Exception e) {
e.printStackTrace();
}
You can set auto cancel to remove when user tap on this
mBuilder.setAutoCancel(true);
Starting your own activity while tap on notification - set your activity
name inside intent
Intent resultIntent = new Intent(this, Youractivty.class);
Reference URL
I will try it must for my new android. Thanks for sharing. desktop alerting software
ReplyDeleteI think you have not read blog comment policy
ReplyDelete