android - onRegistered() is called but onMessage() not -
i have below 2 methods in class gcmintentservice, onregistered() method gets called upon registeration regid, however, when send message onmessage() not called.
@override protected void onregistered(context context, string registrationid) { log.i(tag, "onregistered called"); gcmregistrar.setregisteredonserver(context, true); } @override protected void onmessage(context context, intent intent) { log.i(tag, "received message"); sendnotification("a", "b"); }
below manifest
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="com.myapp.permission.c2d_message" /> <uses-permission android:name="com.google.android.c2dm.permission.receive" /> <uses-permission android:name="android.permission.read_phone_state" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.vibrate" /> <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="com.myapp.gcmintentservice" />
i getting registration id :
regid = getregistrationid(context); //check if have registered. if (regid.length() == 0) { gcmregistrar.checkdevice(myactivity.this); gcmregistrar.checkmanifest(myactivity.this); gcmregistrar.register(myactivity.this, sender_id); } else { log.i(tag, "you registered."); log.i(tag, "the registration id : " + regid); }
in manifest, use below code receive message:
<permission android:name="com.myapp.permission.c2d_message" android:protectionlevel="signature" /> <uses-permission android:name="com.myapp.permission.c2d_message" /> <!-- app has permission register , receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.receive" />
Comments
Post a Comment