Reputation: 1384
I want to set custom Alert sound for GCM notifications..Here is my current coding..
Uri notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(
context.getApplicationContext(), notification);
if(r!= null){
r.play();
}
Intent i = new Intent(context.getApplicationContext(),
CjStartingActivity.class);
I have mp3 file in Res folder (Res.raw.mi.mp3).
Upvotes: 0
Views: 1711
Reputation: 104
Use following Code:-
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, LoginActivity.class);
intent.putExtra(IAppConstants.IS_NOTIFICATION, true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.notification_icon)
.setContentTitle("App Name")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg).setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Uri uri =Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.sound);
Ringtone ring = RingtoneManager.getRingtone(getApplicationContext(), uri);
ring.play();
// for vibrating phone
((Vibrator) getApplicationContext().getSystemService(
Context.VIBRATOR_SERVICE)).vibrate(800);
}
Upvotes: 3