这是我针对 packageNameSuffix 的 GCM 问题的解决方案。
主要问题是权限名称应具有“.debug”后缀。我将该权限用于调试和发布合并到最终清单的清单。
AndroidManfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.experiment.myapplication"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
调试 AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.experiment.myapplication">
<permission android:name="com.experiment.myapplication.debug.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.experiment.myapplication.debug.permission.C2D_MESSAGE" />
<application>
<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.experiment.myapplication.debug" />
</intent-filter>
</receiver>
</application>
</manifest
>
发布 Android 清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.experiment.myapplication" >
<permission android:name="com.experiment.myapplication.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.experiment.myapplication.permission.C2D_MESSAGE" />
<application>
<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.experiment.myapplication" />
</intent-filter>
</receiver>
</application>
</manifest>