相关疑难解决方法(0)

Android 9.0 NotificationManager.notify()抛出java.lang.SecurityException

我自己无法重现此问题,但到目前为止有5位用户报告了此问题。我最近确实发布了一个应用程序更新,将目标SDK从27更改为28,我当然也参与其中。所有5位用户都在某种Pixel设备上运行某种Android 9。我也是

该应用程序通过调用设置通知并调用NotificationManager.notify()来响应警报情况。此通知引用了一个尝试播放位于外部存储器上的音频文件的通知通道。我的应用程序确实在清单中包含READ_EXTERNAL_STORAGE权限。但是由于它本身不能访问外部存储中的任何内容,因此它没有要求用户授予该权限。

当我在Pixel上执行此操作时,效果很好。但是有5位用户报告说它抛出了异常

java.lang.RuntimeException: Unable to start activity ComponentInfo{net.anei.cadpage/net.anei.cadpage.CadPageActivity}: java.lang.SecurityException: UID 10132 does not have permission to content://media/external/audio/media/145 [user 0]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2914)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3049)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6680)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.SecurityException: UID 10132 does not have permission to content://media/external/audio/media/145 [user 0]
at android.os.Parcel.createException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1918)
at android.os.Parcel.readException(Parcel.java:1868)
at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:1559)
at android.app.NotificationManager.notifyAsUser(NotificationManager.java:405)
at android.app.NotificationManager.notify(NotificationManager.java:370)
at android.app.NotificationManager.notify(NotificationManager.java:346)
at net.anei.cadpage.ManageNotification.show(ManageNotification.java:186)
at net.anei.cadpage.ReminderReceiver.scheduleNotification(ReminderReceiver.java:46)
at net.anei.cadpage.ManageNotification.show(ManageNotification.java:161)
at …
Run Code Online (Sandbox Code Playgroud)

notifications android android-securityexception android-9.0-pie

5
推荐指数
1
解决办法
849
查看次数