मैंने अपने जीसीएमआईएनटीन्ट्स सेवा में एक कोड लिखा है जो कई उपयोगकर्ताओं को पुश नोटिफिकेशन भेजता है। मैं अधिसूचना प्रबंधक का उपयोग करता हूं जो अधिसूचना क्लिक होने पर वर्णन एक्टिविटी क्लास को कॉल करेगा। मैं भी भेज event_id DescriptionActivityलंबित इरादे का उपयोग कर putExtra
protected void onMessage(Context ctx, Intent intent) {
message = intent.getStringExtra("message");
String tempmsg=message;
if(message.contains("You"))
{
String temparray[]=tempmsg.split("=");
event_id=temparray[1];
}
nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
intent = new Intent(this, DescriptionActivity.class);
Log.i("the event id in the service is",event_id+"");
intent.putExtra("event_id", event_id);
intent.putExtra("gcmevent",true);
PendingIntent pi = PendingIntent.getActivity(this,0, intent, 0);
String title="Event Notifier";
Notification n = new Notification(R.drawable.defaultimage,message,System.currentTimeMillis());
n.setLatestEventInfo(this, title, message, pi);
n.defaults= Notification.DEFAULT_ALL;
nm.notify(uniqueID,n);
sendGCMIntent(ctx, message);
}
यहाँ event_id कि मैं उपरोक्त विधि में हो रही करने के लिए GCMIntentService फार्म सही यानी मैं हमेशा अद्यतन एक मिल है। लेकिन नीचे दिए गए कोड में (विवरण एक्टिविटी.जावा):
intent = getIntent();
final Bundle b = intent.getExtras();
event_id = Integer.parseInt(b.getString("event_id"));
इवेंट_आईडी हमेशा "5" होता है। कोई फर्क नहीं पड़ता कि मैंने GCMIntentService क्लास में एक्स्ट्रा रखा है, event_id मुझे हमेशा मिलता है 5. क्या कोई समस्या को इंगित कर सकता है? लंबित इरादे के कारण है? यदि हां, तो मुझे इसे कैसे संभालना चाहिए?
धन्यवाद बहुत आदमी! यह काम किया :) – Nemin
बहुत बढ़िया जवाब! धन्यवाद। –
यदि यह स्पष्ट नहीं था: लंबित INTent pi = लंबित INTent.getActivity (यह, 0, इरादा, लंबित INTent.FLAG_CANCEL_CURRENT); – Alecs