我从Android Studio的Android监视器收到该错误。当我通过GCM发送推送通知,在真实设备中,并且应用尚未启动或被迫停止时,会出现此错误。昨天一切正常,今天根本不工作(只有当应用程序在后台或前台运行时才有效)。错误广播意图回调:结果= CANCELED forIntent {act = com.google.android.c2dm.intent.RECEIVE pkg = com.flagg327.guicomaipu(有额外)}
我认为这可能是一个AndroidManifest
错误,但我厌倦了寻找问题,找不到任何东西。
清单
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flagg327.guicomaipu">
...
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
...
<!--GOOGLE CLOUD MESSAGE-->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- for Gingerbread GSF backward compat -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.flagg327.guicomaipu" />
</intent-filter>
</receiver>
<service
android:name="com.flagg327.guicomaipu.gcm.RegistrationService"
android:exported="false" />
<service
android:name="com.flagg327.guicomaipu.gcm.TokenRefreshListenerService"
android:exported="false">
<intent-filter>
<action
android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name="com.flagg327.guicomaipu.gcm.NotificacionsListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</aplication>
<permission
android:name="com.flagg327.guicomaipu.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.flagg327.guicomaipu.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
TokenRefreshListenerService.java
每天登记 '令牌' 更新。因此,每个使用GCM的Android应用都必须有一个InstanceIDListenerService来管理这些更新。
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自动显示的推送通知,但只有当相关联的应用程序有一个GCMListenerService
public class NotificacionsListenerService extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
Log.d("A", "onMessageReceived()");
// Do something
}
}
RegistrationService.java
GCM识别Android设备使用情况g注册卡('令牌')。我的应用程序应该能够从安装它的每个Android设备注册。
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);
}
}
错误
,当我通过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) }
昨天工作...任何想法?比你的时间。
从此[线程]根据(https://groups.google.com/forum/#!msg/android-gcm/MqVlA3Sj26c/6O4TdU1pm0UJ),当接收应用程序是在停止发生此问题设备上的状态(例如,通过设置强制停止)。手动启动时,它只会再次开始接收消息。你也可以检查这[相关SO帖子](http://stackoverflow.com/questions/11902947/broadcast-intent-callback-result-cancelled-forintent)。 – abielita
Sloved检查此..https://stackoverflow.com/a/45810771/1993001 –