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

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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 started yet or has been forced to stop. Yesterday all works fine, today is not working at all (works only if the app is running in background or foreground).

I think this may be an AndroidManifest error, but I'm tired of looking for the problem and can not find anything.

Manifest

      ...                ...                   

TokenRefreshListenerService.java

The registration 'tokens' updates every day. It because that, each Android app that uses GCM must have an InstanceIDListenerService that manages those updates.

public class TokenRefreshListenerService extends InstanceIDListenerService{      @Override     public void onTokenRefresh() {         // Launch the registration process.         Intent i = new Intent(this, RegistrationService.class);         startService(i);     } } 

NotificacionsListenerService.java

GCM automatically shows up the push notifications, but only if the associated app has a GCMListenerService

public class NotificacionsListenerService extends GcmListenerService {      @Override     public void onMessageReceived(String from, Bundle data) {         Log.d("A", "onMessageReceived()");          // Do something      } } 

RegistrationService.java

GCM identifies the Android devices using registration cards('tokens').My app should be able to register from each Android device on which it is installed.

public class RegistrationService extends IntentService {      /**      * Constructor      */     public RegistrationService() {         super("RegistrationService");     }      @Override     protected void onHandleIntent(Intent intent) {         // Generate or download the registration 'token'.         InstanceID myID = InstanceID.getInstance(this);          String registrationToken = null;         try {             // Get the registration 'token'.             registrationToken = myID.getToken(                     getString(R.string.gcm_defaultSenderId),                     GoogleCloudMessaging.INSTANCE_ID_SCOPE,                     null             );              // Subscribe to a topic. The app is able now to receive notifications from this topic.             GcmPubSub subscription = GcmPubSub.getInstance(this);             subscription.subscribe(registrationToken, "/topics/guico_maipu_topic", null);         } catch (IOException e) {             e.printStackTrace();         }          Log.e("Registration Token", registrationToken);     } } 

Error

This error appears when I send a push notification via python.

09-13 21:21:44.800 1851-1851/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.flagg327.guicomaipu (has extras) } 

Yesterday was working... Any idea? Than you for your time.

回答1:

I got the same Error

09-13 21:21:44.800 1851-1851/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.XXX.XXX (has extras) } 

after killing the app.

After some research I realized, that this is only a "Debug-Issue". A "signed APK" handles the broadcast correctly even if the app has been shut down.

Hope it helps!



回答2:

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

    

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.



回答3:

After digging into why this happens, it appears that it happens if you kill the app from Android Studio.

If you open the app from the launcher and swipe it away, your app will still receive notifications.

(Tested on OnePlus One with FCM not GCM)



回答4:

I was also facing the issue. When I remove application from stack, push notification not received. After lots of Google, I found that few phones have battery optimization feature and this will disable background run of applications. When I enable that my application can also run in background. Push notification working fine. Only few application like What's application etc can only have default enable feature. You can have a look on this below URL.

https://github.com/firebase/quickstart-android/issues/89



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!