Gcm phone_registration_error

£可爱£侵袭症+ 提交于 2020-01-04 04:15:50

问题


I'm trying to set up an application to work with gcm but every time I get the phone_registration_error error according to the Gcm documentation this error means:

Incorrect phone registration with Google. 
This phone doesn't currently support GCM.

But I don't understand why my it's not supported, I tested this on a real android device and a emulator with the google api's

My MainActivity:

    @Override
public void onCreate(Bundle savedInstanceState) {
    checkNotNull(SENDER_ID, "SENDER_ID");

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);

    final String regId = GCMRegistrar.getRegistrationId(this);
    Log.i(TAG,  "registration id =====  "+regId);
    if(regId.equals("")){
        GCMRegistrar.register(this, SENDER_ID);

    } else {
        Log.v(TAG, "Already Registred");
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

}

And my manifest:

Manifest on pastebin


回答1:


GCM only works on devices that run android 2.2 or newer. Also GCM only works if a google account is installed for the device. This is also the reason google recommend using <uses-permission android:name="android.permission.GET_ACCOUNTS" /> in the manifest so you are sure the device has a google account.




回答2:


I had the same issue and after seraching on the internet for many days I noticed this in the google groups (https://groups.google.com/forum/#!topic/cerberus-support-forum/eJxOsYqkTxo) and tried it and it worked flawlessly for me.

There is something wrong with your Google account. Please try this:

  • Go to Settings -> Applications -> Manage applications -> All

or

Go to Settings -> Apps-> All (on newer versions)

  • Select "Clear data" for "Google Play services" and "Google services framework"
  • Reboot the phone

Then check for the GCM id from your app.

If it still doesn't work then remove all your google accounts from the phone and reboot the phone and add the account again.

It worked for me (after implementing many solutions that I got from searching the internet.)

Hope it helps!!




回答3:


i looked in your manifest and you forgot to pass GooglePlay Services metadata.

  1. Verify if you have linked GooglePlay services library to your project

  2. Try to add this in your

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

It works nicely for me.

Then recompile and retry. Hope it helps.



来源:https://stackoverflow.com/questions/12772086/gcm-phone-registration-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!