小编Ful*_*oin的帖子

Google Cloud Messaging注册失败

问题解决了 更新:

我解决了这个问题.问题在于方法registerGCMInBackground(). GoogleCloudMessaging.getInstance()期待ApplicationContext.

    private void registerGCMInBackground(final String userId) {
    new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String msg = "";
            Log.d("Register GCM", "started");
            try {
                if (gcm == null) {
                    //PROBLEM SOLVED HERE
                    gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
                    Log.d("GCM", gcm.toString());
                }



                regid = gcm.register(SENDER_ID); //////NULL POINTER EXCEPTION
                msg = "Device registered, registration ID=" + regid;



                // You should send the registration ID to your server over HTTP
                sendRegistrationIdToBackend(userId, regid);

                // For this …
Run Code Online (Sandbox Code Playgroud)

android google-cloud-messaging google-play-services

7
推荐指数
1
解决办法
5379
查看次数