gcm getMessageType(intent)始终返回null

时间:2014-12-11 13:57:47

标签: android android-manifest google-cloud-messaging

当我在扩展IntentService的类中调用函数gcm.getMessageType(intent)时,我只能为messageType获取null。我确定intent参数是我在BroadcastReceiver中收到的意图。

在页面GCM returns a null message type中他们说问题或多或少与清单文件有关,但是我检查了我的文件并找不到原因。我使用的示例来自http://www.grokkingandroid.com/?s=gcm&x=0&y=0

我的AndroidManifest.xml如下所示。非常感谢,如果有人能帮助我解决这个问题。我困在这个问题好几天了。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.grokkingandroid.sampleapp.samples.gcm"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<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" />


<permission
    android:name="com.grokkingandroid.sampleapp.samples.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.grokkingandroid.sampleapp.samples.gcm.permission.C2D_MESSAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/gcm_demo_app_name"
    android:theme="@style/DemoAppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.grokkingandroid.sampleapp.samples.gcm.GCMDemoActivity"
        android:label="@string/gcm_demo_title_activity_gcm_demo" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.grokkingandroid.sampleapp.ACTION_START" />

            <data
                android:host="grokkingandroid.com"
                android:path="/samples/gcm demo"
                android:scheme="app" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.grokkingandroid.sampleapp.samples.alert.AlertListActivity"
        android:label="@string/Emergency_warning" >
    </activity>

    <activity
        android:name="com.grokkingandroid.sampleapp.samples.description.DescriptionActivity"
        android:exported="false"
        android:label="@string/gcm_demo_title_activity_description" />

    <receiver
        android:name="com.grokkingandroid.sampleapp.samples.gcm.GcmBroadcastReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.grokkingandroid.sampleapp.samples.gcm" />
        </intent-filter>
    </receiver>

    <service android:name="com.grokkingandroid.sampleapp.samples.gcm.GcmIntentService" />
</application>

0 个答案:

没有答案