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

前端 未结 8 2086
长情又很酷
长情又很酷 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 18:56

    This is because your app is optimized for battery usage to disable that and receive notification even when your app isn't running in background

    Add this permission to manifest

    
    

    While first launch of your app request user for permission to ignore this app for battery optimization

     if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                Intent intent = new Intent();
                String packageName = getPackageName();
                PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
                if (!pm.isIgnoringBatteryOptimizations(packageName)) {
                    intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
                    intent.setData(Uri.parse("package:" + packageName));
                    startActivity(intent);
                }
            }
    

提交回复
热议问题