GCM SERVICE_NOT_AVAILABLE on Android 2.2

后端 未结 9 1555
青春惊慌失措
青春惊慌失措 2020-11-27 06:21

I am getting the error \"SERVICE_NOT_AVAILABLE\" on my GoogleCloudMessaging.register() call on a Android 2.2 device.

I am writing an app that uses GoogleCloudMessagi

9条回答
  •  离开以前
    2020-11-27 06:31

    I experienced the same problem. GCM works fine on my Tablet running Android 4.04, but always received a SERVICE_NOT_AVAILABLE on my smartphone running Android 2.3.

    I found following workaround not using (so far as I know) any deprecated classes. Add the action "com.google.android.c2dm.intent.REGISTRATION" to the GCMBroadcastReceiver in your manifest. This will enable to receive the registration_id at your GCMBroadcastReceiver.

    
          
             
             
    
             
          
    
    

    After that your GCMBroadcastReceiver is able to receive the registration_id:

    public void onReceive(Context context, Intent intent) {
       String regId = intent.getExtras().getString("registration_id");
       if(regId != null && !regId.equals("")) {
          /* Do what ever you want with the regId eg. send it to your server */
       }
    }
    

    Although I still get a SERVICE_NOT_AVAILABLE error, I can handle the registration_id in my GCMBroadcastReceiver and I am able to send messages to my smartphone. Quite weird, but it works for me.

提交回复
热议问题