How To Get Gcm Notification Messages Into An Activity In Android?
Explanation: I am using GCM to send notification to the users.Everything is completed.I was created a server side programming to create a rest for push_message and all t
Solution 1:
The code you've posted is an IntentService
that registers a device for your server with GCM.
The code you need to receive messages from GCM is here:
Basically, you need to create your own GcmListenerService
.
Don't forget to put all your services and receivers into AndroidManifest.xml
. It should look something like this:
<!-- [START gcm_receiver] --><receiverandroid:name="com.google.android.gms.gcm.GcmReceiver"android:exported="true"android:permission="com.google.android.c2dm.permission.SEND" ><intent-filter><actionandroid:name="com.google.android.c2dm.intent.RECEIVE" /><categoryandroid:name="your package" /></intent-filter></receiver><!-- [END gcm_receiver] --><!-- [START gcm_listener] --><serviceandroid:name=".MyGcmListenerService"android:exported="false" ><intent-filter><actionandroid:name="com.google.android.c2dm.intent.RECEIVE" /></intent-filter></service><!-- [END gcm_listener] --><!-- [START instanceId_listener] --><serviceandroid:name=".MyInstanceIDListenerService"android:exported="false"><intent-filter><actionandroid:name="com.google.android.gms.iid.InstanceID"/></intent-filter></service><!-- [END instanceId_listener] --><serviceandroid:name=".GcmIntentService"android:exported="false"></service>
Solution 2:
All you need to do is create one service that implements GcmListenerService.
publicclassEMSListenerServiceextendsGcmListenerService {
privatestatic final StringTAG = "ems_service";
@OverridepublicvoidonMessageReceived(Stringfrom, Bundle data) {
super.onMessageReceived(from, data);
Display.log(TAG, "EMS received");
}
}
And when you receive the message you need to broadcast to the activity using LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
Post a Comment for "How To Get Gcm Notification Messages Into An Activity In Android?"