Android Gcm Notification Builder Features Not Working When App Is Closed
I have created an app that is receiving GCM notifications correctly. When I have the app open the notification is ringing and also the notification comes properly as a big box as d
Solution 1:
put it onReceive
ActivityManageram= (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentNamecomponentInfo= taskInfo.get(0).topActivity;
if(componentInfo.getPackageName().equalsIgnoreCase("com.example.myapp")){
updateMyActivity(message); //send broadcast to notify app//Activity Running// Send a broadcast with the intent-filter which you register in your activity// where you want to have the updates
}
else{
//Activity Not Running//Generate Notification
sendNotification(message);
}
and call this method
privatevoidsendNotification(String message) {
Intentintent=newIntent(this,FullMapActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// int color = getResources().getColor(R.color.my_notif_color);PendingIntentpendingIntent= PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
/*PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 *//* Request code *//*, intent,
PendingIntent.FLAG_ONE_SHOT);*/
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
NotificationCompat.BuildernotificationBuilder=newNotificationCompat.Builder(this)
.setSmallIcon(R.drawable.headerlogo)
.setContentTitle("hey..! your booking is confirmed")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManagernotificationManager=
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0/* ID of notification */, notificationBuilder.build());
}
else
{
NotificationCompat.BuildernotificationBuilder=newNotificationCompat.Builder(this)
.setSmallIcon(R.drawable.headerlogo)
.setContentTitle("hey..! your booking is confirmed")
.setContentText(message)
.setAutoCancel(true)
// .setColor(color)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManagernotificationManager=
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0/* ID of notification */, notificationBuilder.build());
}
}
Post a Comment for "Android Gcm Notification Builder Features Not Working When App Is Closed"