我正在研究GCM。我的应用程序甚至没有启动并变得混乱。跟随错误
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- FOR GCM START1 -->
<permission
android:name="com.ama.gcmdemo.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.ama.gcmdemo.permission.C2D_MESSAGE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- FOR GCM END1 -->
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
<activity
android:name="com.ama.gcmdemo.MainActivityActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
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" />
<category android:name="com.ama.gcmdemo" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
<service android:name=".DialogService" />
</application>
收到以下错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ama.gcmdemo/com.ama.gcmdemo.MainActivityActivity}: java.lang.IllegalStateException: Application does not define permission com.ama.gcmdemo.permission.C2D_MESSAGE
主要活动在com.ama.gcmdemo包下直接进行。
请说明故障在哪里
答案 0 :(得分:0)
在清单文件中提供此权限
<permission
android:name="<package-name>.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="<package-name>.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
代替package-name,提供您的包名称
答案 1 :(得分:0)
试试这个..
只需更改接收器内的以下行,
android:name="com.google.android.gcm.GCMBroadcastReceiver"
要,
android:name="com.ama.gcmdemo.GCMBroadcastReceiver"
并确保您的包中有GCMBroadcastReceiver.java
。 Bcs,你应该在你的包中有接收器来接收GCM消息。
答案 2 :(得分:0)
您需要使用GCM包名称而不是应用程序包名称定义您的接收者,如下所示:
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver">
不会强>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"