gpt4 book ai didi

android - GCM 接收信号但不调用 OnReceive() result=CANCELLED

转载 作者:行者123 更新时间:2023-11-29 17:47:29 27 4
gpt4 key购买 nike

每当我尝试从 Android Studio 中内置的演示 GoogleAppEngine 页面发送消息时,我都会在 LogCat 中收到此消息。

:GCM message com.objectivetruth.uoitlibrarybooking >0:1408853167972751%99d31532f9fd7ecd
:broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.objectivetruth.uoitlibrarybooking (has extras) }
:Unregister application com.objectivetruth.uoitlibrarybooking for user 0
:Implicit intents with startService are not safe: Intent { act=com.google.android.c2dm.intent.UNREGISTER (has extras) } android.content.ContextWrapper.startService:494 ftg.a:1607 ftg.a:361

在关注this guide 之后,我要扯掉我的头发了从谷歌从头开始两次,以确保我完全遵循它,并且我的设备上不断出现相同的错误

疯狂的是它的增长,如果我发送另一条消息,将会有一连串的调用,我假设是,所有以前尚未处理的消息。我尝试了一个本地 GAE 实例,然后将其上传到云端,但仍然是同样的问题。注册工作正常 AFAIK。我举杯 toast ,告诉我生成的注册码,我认为这意味着它成功了。此外,每次发生新注册时,本地服务器都会向我显示,所以我认为这也很好

这是我已经四重检查过的应用程序 list 的相关部分:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission
android:name="com.objectivetruth.uoitlibrarybooking.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.objectivetruth.uoitlibrarybooking.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.objectivetruth.uoitlibrarybooking" />
</intent-filter>
</receiver>

<service android:name=".GcmIntentService" />

和 GcmBroadcastReceiver

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Timber.i("Please please call me!");
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}

这是 GcmIntentService

public class GcmIntentService extends IntentService {

public GcmIntentService() {
super("GcmIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);

if (extras != null && !extras.isEmpty()) { // has effect of unparcelling Bundle
// Since we're not using two way messaging, this is all we really to check for
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Timber.i(extras.toString());

showToast(extras.getString("message"));
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}

protected void showToast(final String message) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
});
}
}

AsyncGcmRegistration 是从指南中复制/粘贴的

真的不知道还有什么问题..

最佳答案

OMG,如果将来有人偶然发现这个问题并且像我一样焦头烂额,你得到 result=canceled 的原因是因为 Intent 的去向存在合法问题。

不要忽略它。

在我的例子中,我的接收声明位于我的标签之外,因此它无法正确识别 pkg。

不要忽略 list ,如果您因为它而无法获得很高的机会。

关于android - GCM 接收信号但不调用 OnReceive() result=CANCELLED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25468562/

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