मेरे पास एक ऐसा एप्लिकेशन है जो मूल रूप से एक वेबव्यू और जीसीएम नोटिफिकेशन है। मैं निम्नलिखित बातों को प्राप्त करना चाहता हूं: यदि उपयोगकर्ता ऐप में है और अधिसूचना प्राप्त करता है, तो जब वह अधिसूचना पर क्लिक करता है तो मैं चाहता हूं कि वेब्यूव्यू अधिसूचना में प्रदान किए गए यूआरएल को लोड करे।अधिसूचना पर प्रसारण भेजें
मैं प्रसारण रिसीवर का उपयोग करके इसे पूरा करने की कोशिश कर रहा हूं लेकिन यह काम नहीं करता है।
मैं गतिशील MainActivity में रिसीवर रजिस्टर:
private void registerNotificationReceiver() {
final IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_LOAD_URL_FROM_NOTIFICATION);
Log.i(TAG, "registerNotificationReceiver()");
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "notification received");
}
};
super.registerReceiver(this.receiver, filter);
}
और GCM श्रोता में मैं PendingIntent.getBroadast() का उपयोग कर रहा:
final Intent broadcastIntent = new Intent(MainActivity.ACTION_LOAD_URL_FROM_NOTIFICATION);
PendingIntent intent = PendingIntent.getBroadcast(getApplicationContext(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(intent);
notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notification);
मैं में क्यों onReceive समझ में नहीं आता मुख्य गतिविधि वर्ग को नहीं कहा जाता है। "अधिसूचना प्राप्त" संदेश प्रदर्शित नहीं होता है। क्या आप मेरी मदद कर सकते हैं? धन्यवाद :)
हाँ, यह अब काम करता है जब रिसीवर प्रकट में परिभाषित किया गया है। धन्यवाद :) मेरा लक्ष्य प्राप्त करने के लिए मुझे मुख्य गतिविधि में एक और रिसीवर का उपयोग करने की आवश्यकता है, जहां मैं यूआरएल लोड करता हूं। इसका प्रसारण पहले रिसीवर (जिसे मैंने मैनिफेस्ट में परिभाषित किया) से भेजा है। यह अब काम करता है, लेकिन मुझे उस दृष्टिकोण को पसंद नहीं है। यह मुझे एक बुरा अभ्यास के रूप में देखता है ... – definera
यह * अनिवार्य * अभ्यास है ... भगवान गूगल ऐसा कहता है ... – eduyayo