2011-10-14 83 views
3

有關如何解決此權限拒絕錯誤重試註冊事件的任何想法,非常感謝。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 

清單

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

所有有利於這項工作首次登記的代碼!

回答

4

問題解決 我需要重試事件一個單獨的接收申報艙單我

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

所有現在是很好的,雖然我不明白爲什麼這會解決它顯然不會的問題!

+0

這是因爲android:permission屬性。正如文檔所述(http://developer.android.com/guide/topics/manifest/receiver-element.html#prmsn),廣播公司必須擁有該權限才能向廣播接收方發送消息。 –