Google Cloud 消息接收方意图未启动(广播意图回调:result=CANCEL forIntent)



我正在尝试创建一个GCM客户端,注册很好。我也成功地从服务器发送消息。但是,客户端不会启动意向。它说

09-30 08:39:59.795: W/GTalkService(4667): [DataMsgMgr] 广播意图回调: result=CANCELforIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[dol.framework] (有额外功能) }

我的意图

public class GCMService extends IntentService{
    public GCMService(String name) {
        super("GCMService");
    }
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        String messageType = gcm.getMessageType(intent);
        android.util.Log.i("hi","test");
        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                Logger.logInUI(tag, "Received: " + extras.toString());
            }
        }
        GCMReceiver.completeWakefulIntent(intent);
    }
}

还有我的接收器

public class GCMReceiver extends WakefulBroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        ComponentName comp = new ComponentName(context.getPackageName(),
                GCMService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        Logger.log("hi","eetett");
        setResultCode(Activity.RESULT_OK);
    }
}

最后是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dol.framework"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission android:name="dol.framework.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="dol.framework.gcm.permission.C2D_MESSAGE" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:name="dol.framework.widget.DolApplication"
        android:label="Dol Framework"
        android:theme="@style/AppTheme" >
        <activity
            android:name="dol.framework.activity.DebugActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
            android:name="dol.framework.GCMReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="dol.framework" />
            </intent-filter>
        </receiver>
        <service android:name="dol.framework.GCMService"/>
    </application>
</manifest>

对不起,文字墙。GCMService和GCMReceiver都在我的软件包(dol.framework)的顶部。我做错了什么?除了这些,我做的不多。仅注册设备,然后我向此设备发送消息。日志在顶部打印消息,但不执行任何操作。我不应该开始服务或其他东西吗? 我没有在示例中看到任何相关内容。

在您定义并用于 GCM 的权限中,您具有 dol.framework.gcm.permission。它应该是 dol.framework.permission,因为你的应用包是 dol.framework。

尝试将清单的接收方位更改为以下内容:

   <receiver
        android:name=".GCMReciever"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="dol.framework" />
        </intent-filter>
    </receiver>

最新更新