GCM Android: onRegistered () is not called

I have a problem with GCM on Android. It cannot call the onRegistered() or ever return a good regId on one of my test devices (Droid2), but it works fine on the other device (Galaxy Nexus).

I follow the basic example here . The caller is as follows:

 GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) GCMRegistrar.register(this, Constants.SENDER_ID); else Log.v(TAG, "Already registered"); 

And my manifest has this:

 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> 

and

 <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.gcl.myapp" /> </intent-filter> </receiver> 

Why doesn't the onRegistered() callback work? And what can make it work on one device, but fail on another? Thanks.

+4
source share
2 answers

If this works on some devices, but not on others, this is due to one of the following:

  • Before Android 4.0.4, a valid google account is required for the device to work.
  • GCM only works on devices with the Play Store App and API 8 onwards.
  • Your manifest is poorly formatted - use Lint to verify!
  • The device / application is already registered, the playback implementation may not return again. First try GCMRegistrar.unregister(this); .

Hope this helps!

+5
source

I had the same problem. If you are using AngularJS + IonicFramework, you do not need to do this:

After creating the factory using the onDeviceReady function, the onNotificationGCM function is created. Something like that:

 app.factory('PushProcessingService', function () { .. }); function onNotificationGCM(e) { } 

I created onNotificationGCM inside my factory. This solves my problem.

0
source

Source: https://habr.com/ru/post/1446810/


All Articles