Instead of :
notificationManager.notify(unique_id, notification);
use
notificationManager.notify((int) when , notification);
Hope this helps.
Pregunta
I receive multiple notification successfully using the notification intent below. But when i click on any notification it opened the last notification received everytime. can someone tell me how to open corresponding notification. i means each notification has its own content.
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
/*
* Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GCMIntentService.class.getName());
Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
*
*/
GCMNotificationUtility.notiMsg = intent.getStringExtra("msg");
GCMNotificationUtility.notPubDate = chopJson(intent.getStringExtra("datepublished"));
GCMNotificationUtility.notDescription =chopJson(intent.getStringExtra("description"));
GCMNotificationUtility.notLink = chopJson(intent.getStringExtra("news_url"));
GCMNotificationUtility.notCategory= chopJson(intent.getStringExtra("category"));
int icon = R.drawable.ic_launcher; // icon from resources
CharSequence tickerText =context.getResources().getString(R.string.app_name);//intent.getStringExtra("me"); // ticker-text
long when = System.currentTimeMillis(); // notification time
CharSequence xmsg =GCMNotificationUtility.notiMsg;
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, tickerText, when);
System.out.println("nodescription "+GCMNotificationUtility.notDescription);
ActusNewActivity.description=GCMNotificationUtility.notDescription;
ActusNewActivity.pudDate=GCMNotificationUtility.notPubDate;
ActusNewActivity.Link=GCMNotificationUtility.notLink;
ActusNewActivity.title=GCMNotificationUtility.notiMsg;
Intent notificationIntent = new Intent(context,ActusNewActivity.class);
Calendar c = Calendar.getInstance();
int unique_id = (int) c.getTimeInMillis();
//set calendar.getTimeInMillis() as unique ID.
PendingIntent pendingIntent = PendingIntent.getActivity(context, unique_id , notificationIntent, PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(context,tickerText,xmsg, pendingIntent);
notification.flags|=notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS;
notification.vibrate=new long[] {100L, 100L, 200L, 500L};
notificationManager.notify(unique_id, notification);
GCMNotificationUtility.notificationReceived=true;
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire();
}
public String chopJson(String y){
String x = ":\"";
int xval = y.indexOf(x)+2;
String substring = y.substring(0, xval);
String newElement = y.replace(substring, "");
int lastvalue = newElement.length()-2;
String value = newElement.substring(0,lastvalue);
return value;
}
Solución
Instead of :
notificationManager.notify(unique_id, notification);
use
notificationManager.notify((int) when , notification);
Hope this helps.