相关疑难解决方法(0)

即使应用关闭(滑动/滑动)也会收到GCM消息

这是在MainActivity中用作BroadcastReceiver的代码

 //Initializing our broadcast receiver
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        //When the broadcast received
        //We are sending the broadcast from GCMRegistrationIntentService

        @Override
        public void onReceive(Context context, Intent intent) {
            //If the broadcast has received with success
            //that means device is registered successfully
            if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_SUCCESS)){
                //Getting the registration token from the intent
                String token = intent.getStringExtra("token");
                //Displaying the token as toast
                Toast.makeText(getApplicationContext(), "Registration token:" + token, Toast.LENGTH_LONG).show();

                //if the intent is not with success then displaying error messages
            } else if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_ERROR)){
                Toast.makeText(getApplicationContext(), …
Run Code Online (Sandbox Code Playgroud)

android google-cloud-messaging firebase-cloud-messaging

5
推荐指数
1
解决办法
8068
查看次数