非常感谢您提供有关如何解决重试注册事件中此权限拒绝错误的任何想法.
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
表现
android:protectionLevel="signature" />
android:label="@string/app_name">
android:permission="com.google.android.c2dm.permission.SEND">
...
设置重试的代码
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);
}
一切对第一次使用的注册都是有益的!
解决方法:
问题解决了
我在清单中为重试事件需要单独的接收者声明
android:permission="com.google.android.c2dm.permission.SEND">
现在一切都很好,尽管我不明白为什么这可以解决明显的问题!
标签:android-c2dm,android
来源: https://codeday.me/bug/20191102/1988910.html