android - GCM clarifications -
i know these methods deprecated, since new gcm api seems buggy, reverting these methods until stable version pushed google.
we declaring receiver inside manifest.
<receiver android:name="com.google.android.gcm.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <!-- receives actual messages. --> <action android:name="com.google.android.c2dm.intent.receive" /> <!-- receives registration id. --> <action android:name="com.google.android.c2dm.intent.registration" /> <category android:name="com.myapp" /> </intent-filter> </receiver> <service android:name=".gcmintentservice" />
and have onmessage() method inside gcmintentservice class.
@override protected void onmessage(context context, intent intent) { log.i(tag, "received message"); string message = intent.getextras().getstring("msg"); }
1. however, upon receiving message method never called. why ?
moreover, example follow uses following.
registerreceiver(mhandlemessagereceiver, new intentfilter("intent_filter_string"));
associated following class.
private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string newmessage = intent.getextras().getstring("data"); } };
which gets unregistered inside onpause.
- why need create broadcast receiver?
- can't in manifest ?
- isn't covered onmessage() inside gcmintentservice class ?
- what role pending intent string play ?
answers appreciated.
why need create broadcast receiver?
in cases might interested in updating ui if app running. create broadcast receiver @ runtime , unregister when app goes background.
can't in manifest?
yes, can in manifest too.
isn't covered onmessage() inside gcmintentservice class?
gcmintentservice extends gcmbaseintentservice. message coming gcm, first recieved in onmessage of gcmintentservice. upto decide how handle message. can create notification or send broadcast custom broadcast receivers , update ui when app running.
what role pending intent play ?
according docs
a pendingintent reference token maintained system describing original data used retrieve it. means that, if owning application's process killed, pendingintent remain usable other processes have been given it.
Comments
Post a Comment