C2DM retry registration permission denial

女生的网名这么多〃 提交于 2020-01-01 14:49:11

问题


Any ideas on how to solve this permission denial error on retry registration event are greatly appreciated.

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

manifest

    <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>
...

The code that sets the retry up

    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);
    }

All is good for registrations that work first time!


回答1:


Problem solved I needed a seperate receiver declaration for the retry event in my manifest

    <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>

All is now good although I don't understand why this would solve the issue it clearly does!



来源:https://stackoverflow.com/questions/7764120/c2dm-retry-registration-permission-denial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!