android - Google C2D_MESSAGE 应用程序未定义权限?

标签 android push-notification google-cloud-messaging

我的代码有问题,我刚刚按照 GCM 推送消息的 google 指南进行操作,但收到此错误:

06-07 10:51:04.371: E/AndroidRuntime(29686): FATAL EXCEPTION: main
06-07 10:51:04.371: E/AndroidRuntime(29686): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.droidersuin.project/com.droidersuin.pushnotifications.PushMainActivity}: java.lang.IllegalStateException: Application does not define permission com.droidersuin.project.permission.C2D_MESSAGE
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1959)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1984)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.app.ActivityThread.access$600(ActivityThread.java:126)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1150)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.os.Looper.loop(Looper.java:137)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at android.app.ActivityThread.main(ActivityThread.java:4456)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at java.lang.reflect.Method.invokeNative(Native Method)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at java.lang.reflect.Method.invoke(Method.java:511)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-07 10:51:04.371: E/AndroidRuntime(29686):    at dalvik.system.NativeStart.main(Native Method)
06-07 10:51:04.371: E/AndroidRuntime(29686): Caused by: java.lang.IllegalStateException: Application does not define permission com.droidersuin.project.permission.C2D_MESSAGE
06-07 10:51:04.371: E/AndroidRuntime(29686): 

这是我的 list

 <activity
        android:name="com.droidersuin.pushnotifications.RegisterPushActivity"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
        android:label="@string/app_name" >

    </activity>

    <activity
       android:name="com.droidersuin.pushnotifications.PushMainActivity"
         android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
        android:configChanges="keyboardHidden|orientation" >
    </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.droidersuin.pushnotifications" />
        </intent-filter>
    </receiver>

    <service android:name="com.droidersuin.pushnotifications.GCMIntentService" />


</application>

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />  
<permission 
    android:name="com.droidersuin.pushnotifications.permission.C2D_MESSAGE" 
    android:protectionLevel="signature"/>
<uses-permission android:name="com.droidersuin.pushnotifications.permission.C2D_MESSAGE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

这是我的包裹:

my package

任何人帮助我..?我希望有人可以帮助解决这个问题,当您学习教程时总是会感到沮丧。

最佳答案

添加权限后应该是这样的

<permission android:name="your package name.permission.C2D_MESSAGE"    android:protectionLevel="signature" />
 <uses-permission android:name="your package name.permission.C2D_MESSAGE" />

关于android - Google C2D_MESSAGE 应用程序未定义权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16976020/

相关文章:

android - "text selection mode"是否对所有 View 和设备都一样工作

ios4 - iOS 4.x/5.0 - 后台/多任务应用程序的推送通知?

android - 当用户使用不同的智能手机时,如何在 GCM/FCM 中交换 Registration_ID?

android - GCM 服务器知道成功交付

java - Google 云消息注册超时

已安装 Android SDK,但缺少 adb.exe

android - Backendless - Twitter 登录时出现模糊引用错误

android - 如何通过单击取消单击单选按钮来动态删除 LinearLayout?

c# - Windows Phone 上的推送通知可以免费实现吗?

swift - 条件绑定(bind)的初始化程序必须具有可选类型,而不是 'String' ?