How To Set Notification With Custom Sound
I want to use Notification with custom sound like Notification.sounds Thanks
Solution 1:
to show a notification, with sound try:
NotificationCompat.BuildermBuilder=newNotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your appIntentresultIntent=newIntent(this, ResultActivity.class);
// The stack builder object will contain an artificial back stack for the// started Activity.// This ensures that navigating backward from the Activity leads out of// your application to the Home screen.TaskStackBuilderstackBuilder= TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntentresultPendingIntent=
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
// to set custom sound
mBuilder.setSound(YOUR_CUSTOM_URI);
NotificationManagermNotificationManager=
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
For more on setting sounds, look here
Post a Comment for "How To Set Notification With Custom Sound"