GCM接收信号但未调用OnReceive()result = CANCELED

时间:2014-08-24 04:33:55

标签: android google-app-engine google-cloud-messaging

每当我尝试从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告诉我生成的注册码,我认为这意味着它的成功。 此外,本地服务器每次出现新注册时都会显示我,所以我认为这也很好

这是我的应用清单相关部分,我已经检查了四倍:

<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

真的不确定还有什么可能是错的..

1 个答案:

答案 0 :(得分:3)

OMG,如果将来有人偶然发现这件事,并且像我一样撕裂他们的头发,你得到结果=取消的原因是因为这意味着去哪里是合法的问题。

不要忽视它。

在我的情况下,我在标签之外接收了声明,因此无法正确识别pkg。

如果你因为它而获得很高的机会,请不要忽略清单。