我有一个推送通知接收器,在收到后,它将通知设置为下面的函数。
private void sendNotification(String message, int id, String title) {
PendingIntent pendingIntent =
IntentUtil.getSplashActivityNotificationPendingIntent(
this, ConstantValue.GCM_PUSH_ACTIVITY, id, title);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.praiseiconwhite)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle(getString(R.string.notification_title))
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(ConstantValue.GCM_PUSH_NOTIFICATION, notificationBuilder.build());
}
它过去使用GCM,现在改为FCM。最近,我收到了来自Fabric的崩溃报告,指出requires android.permission.READ_EXTERNAL_STORAGE
Fatal Exception: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri
content://media/external/audio/media/1266 from pid=23488, uid=10157
requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1546)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:691)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1113)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:937)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:864)
at android.media.RingtoneManager.isRingtoneExist(RingtoneManager.java:1092)
at android.app.NotificationManager.notify(NotificationManager.java:157)
at android.app.NotificationManager.notify(NotificationManager.java:123)
at com.mypackage.service.CustomFirebaseMessagingService.sendNotification(SourceFile:77)
at com.mypackage.service.CustomFirebaseMessagingService.onMessageReceived(SourceFile:52)
at com.google.firebase.messaging.FirebaseMessagingService.zzo(Unknown Source)
at com.google.firebase.messaging.FirebaseMessagingService.zzn(Unknown Source)
at com.google.firebase.messaging.FirebaseMessagingService.zzm(Unknown Source)
at com.google.firebase.iid.zzb$2.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
我知道 https://stackoverflow.com/a/32617585/3286489 的答案是要求我们请求许可。但是,这是在收到推送通知以设置通知时,此时无法进行用户交互。
此外,需要权限的不是我的代码,而是驻留在设备特定的代码中
at android.os.Parcel.readException(Parcel.java:1546)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
我应该如何解决这个问题?
代码明确指出权限问题。
请按照以下步骤操作:
1-检查您是否已在清单文件中声明了READ_EXTERNAL_STORAGE的权限,如果是,那么它应该在所有设备上工作,直到棒棒糖
2-对于棒棒糖版本后的权限,搜索运行时权限示例,尽管我正在添加链接以一目了然,但您最好仔细阅读该主题,从现在开始对您有用。
安卓运行时权限
祝你好运!