Error broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.flagg327.guicomaipu (has extras) }

前端 未结 8 2066
长情又很酷
长情又很酷 2020-11-27 18:41

I\'m receiving that error from Android Studio\'s Android Monitor. This error appears when I send a push notification through GCM, in a real device, and the app has not been

相关标签:
8条回答
  • 2020-11-27 19:14

    So... I solved the problem. The problem was that the device is not registered to receive GCM if the app is force closed or if the app has never been opened since device boot. The solution is simple, register the device on phone boot. For this, I implemented a BroadcastReceiver and started a process registration inside it.

    The modifications:

    Added to AndroidManifest

        <receiver android:name="com.flagg327.guicomaipu.gcm.OnBootBroadcastReceiver">
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED" />
    
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver>
    

    OnBootBroadcastReceiver.java

    public class OnBootBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
    
            Intent i = new Intent("com.flagg327.guicomaipu.gcm.RegistrationService");
            i.setClass(context, RegistrationService.class);
            context.startService(i);
        }
    }
    

    So, on boot, the device will register into the GCM server and going to be able to receive any push notification from my server. I hope it is useful.

    0 讨论(0)
  • 2020-11-27 19:16

    For me it was the case that AutoStart functionality for my app was provided. Go to settings select your installed app and enable AutoStart. This will fix the issue.

    0 讨论(0)
提交回复
热议问题