android - C2DM 重试注册权限被拒绝

标签 android android-c2dm

非常感谢任何关于如何解决重试注册事件中的权限拒绝错误的想法。

Permission Denial: broadcasting Intent { act=com.google.android.c2dm.intent.RETRY flg=0x4 (has extras) } from com.my.package (pid=-1, uid=10041) requires com.google.android.c2dm.permission.SEND due to receiver com.my.package/com.google.android.c2dm.C2DMBroadcastReceiver

list

    <uses-sdk android:minSdkVersion="8" />
    <permission android:name="com.my.package.permission.C2D_MESSAGE"
       android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="com.google.android.c2dm.permission.SEND" />
    <uses-permission android:name="com.my.package.permission.C2D_MESSAGE" />
    <application android:name=".Sims3" android:icon="@drawable/icon"
         android:label="@string/app_name">
        <provider android:name=".QuizProvider" android:authorities="com.my.package.QuizModel"/>
        <service android:name=".C2DMReceiver" />
        <service android:enabled="true" android:name=".RegService" />
        <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <!-- Receive the actual message -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.my.package" />
            </intent-filter>
            <!-- Receive the registration id -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.my.package" />
            </intent-filter>
            <!-- Handle retry events -->
            <intent-filter>
               <action android:name="com.google.android.c2dm.intent.RETRY"/>
               <category android:name="com.my.package" />
            </intent-filter>
        </receiver>
...

设置重试的代码

    if ("SERVICE_NOT_AVAILABLE".equals(error)) {
        long backoffTimeMs = C2DMessaging.getBackoff(context);

        Log.d(TAG, "Scheduling registration retry, backoff = " + backoffTimeMs);
        Intent retryIntent = new Intent(C2DM_RETRY);
        PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 
                0 /*requestCode*/, retryIntent, 0 /*flags*/);

        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + backoffTimeMs,
                retryPIntent);

        // Next retry should wait longer.
        backoffTimeMs *= 2;
        C2DMessaging.setBackoff(context, backoffTimeMs);
    }

对于第一次成功的注册来说一切都很好!

最佳答案

问题解决了 我需要在我的 list 中为重试事件单独声明接收器

    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <!-- Receive the actual message -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.my.package" />
        </intent-filter>
        <!-- Receive the registration id -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.my.package" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
        <!-- Handle retry events -->
        <intent-filter>
           <action android:name="com.google.android.c2dm.intent.RETRY"/>
           <category android:name="com.my.package" />
        </intent-filter>
    </receiver>

现在一切都很好,虽然我不明白为什么这会解决它显然能解决的问题!

关于android - C2DM 重试注册权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7764120/

相关文章:

c# - Android(c2dm)推送通知错误

android - 使用 PushBots 进行 Android 推送通知

java - 很难理解Android C2DM

Android Studio 0.9.0 - 无法解析符号

android - 更改 "google-service.json"文件后推送通知无法与 FCM 一起使用

android - 在 Android 中使用相机手电筒

android - 不支持 c2dm,还有其他选择吗?

android - 是否可以检测到Android应用程序卸载?

android - 将变形动画从箭头反转为复选标记

android - 如何使用内置(股票)android 浏览器打开网页?