gpt4 book ai didi

android - 错误广播 Intent 回调 : result=CANCELLED forIntent { act=com. google.android.c2dm.intent.RECEIVE pkg=com.flagg327.guicomaipu(有附加功能)}

转载 作者:IT老高 更新时间:2023-10-28 22:25:59 25 4
gpt4 key购买 nike

我从 Android Studio 的 Android 监视器收到了该错误。当我通过 GCM 在真实设备中发送推送通知并且应用程序尚未启动或已被强制停止时,会出现此错误。昨天一切正常,今天根本不工作(仅当应用程序在后台或前台运行时才有效)。

我认为这可能是一个AndroidManifest错误,但是我已经厌倦了寻找问题并且找不到任何东西。

list

<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

注册“ token ”每天都会更新。这是因为,每个使用 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 使用注册卡('tokens')识别 Android 设备。我的应用应该能够从安装它的每个 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) }

昨天还在工作……有什么想法吗?比你花时间。

最佳答案

由于没有答案提供官方链接,我决定询问 firebase 团队并从他们那里得到官方答案

It looks like you have an issue when your app is force stopped or killed. Actually, this is working as intended. The Android framework advises that apps that have been stopped (i.e. killed/force-stopped from Settings) should not be started without explicit user interaction. FCM follows this recommendation and thus its services will not start as well. This also means that messages will not be received (FirebaseMessagingService will not be called) when the app is in "killed" state. Here are some useful links so you could have a better understanding on this topic: https://developer.android.com/about/versions/android-3.1#launchcontrols https://github.com/firebase/quickstart-android/issues/368#issuecomment-343567506

总之:

  • 应用被用户杀死(来自设置/强制停止)将标有一个标志,该标志将无法自动触发任何服务,包括 firebase 消息服务。这与应用程序被系统杀死或从最近的应用程序滑动不同。
  • 但是,在一些来自 VIVO 或 ONEPLUS 的 ROM 上,刷卡功能(单击最近的应用按钮/刷卡)被错误地实现为与设置/强制停止类似。这导致firebase消息服务无法启动。
  • 这里和许多地方都提出了这个问题。 FCM 团队已意识到该问题并正在解决此问题

注意:即使问题是关于 GCM 的,但 FCM 在问题标题中抛出完全相同的错误。

关于android - 错误广播 Intent 回调 : result=CANCELLED forIntent { act=com. google.android.c2dm.intent.RECEIVE pkg=com.flagg327.guicomaipu(有附加功能)},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39480931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com