我有一個推送通知接收器,接收後,然後將通知設置爲以下功能。如何解決在啓動通知時需要android.permission.READ_EXTERNAL_STORAGE?
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。最近,我從面料說明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)
內我應該怎麼解決這個問題呢?
顯然它只發生在兩個設計,DIGICEL DL810,5080Q – Elye
@Jens,對於Mashmallow及以上版本,我相信它需要請求用戶的許可批准,對吧? – Elye
@Jens,我知道這個鏈接。但是,當發送一個推送通知時,用戶不與設備進行交互,如何請求許可以及專家用戶授予它? – Elye