用于运行的应用程序。然而,就在最近它开始停止工作。该设备运行的是 Android Nutella。下面是 LogCat。
java.lang.SecurityException: Permission Denial: reading com.google.android.music.store.ConfigContentProvider uri content://com.google.android.music.ConfigContent/one-key/2/ExplicitRestrictedByParentControl from pid=2500, uid=10373 requires the provider be exported, or grantUriPermission()
应用程序在最后一行的以下代码 fragment (包含在 SongParser 方法中)中崩溃。
String[] projection2 = {MediaStore.Audio.Media.ARTIST};
Uri songUri=null;
try {
songUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
} catch (NullPointerException e){
e.printStackTrace();
}
if (songUri!=null) {
CursorLoader cl2 = new CursorLoader(context,
songUri, projection2, null, null, null);
cursor = cl2.loadInBackground();
在通过运行时权限方法请求权限后,我通过以下方法授予 Uri 权限。
private void startService() {
//start intent to RssService for feedback
intent = new Intent(getActivity(), SongService.class);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
getContext().grantUriPermission("xxx.xxx.xxx.SongService",Uri.parse("content://com.google.android.music.MusicContent/audio"),Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(SongService.RECEIVER, resultReceiver);
getActivity().startService(intent);
}
这里是 SongService 调用 SongParser 的地方。
@Override
protected void onHandleIntent(Intent intent) {
List<String> eventItems= null;
if (haveNetworkConnection()) {
parser = new SongParser();
eventItems = parser.getAllArtists(getApplicationContext());
}
Bundle bundle = new Bundle();
bundle.putSerializable(ITEMS, (Serializable) eventItems);
ResultReceiver receiver = intent.getParcelableExtra(RECEIVER);
receiver.send(0, bundle);}}
我也在 list 中包含了权限。同样,这个异常似乎是自己发生的。
<permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
最佳答案
发生的事情是,出于某种原因,(导出的)MusicContent 提供程序将重定向到 ConfigContentProvider,它未导出。
看来解决方法是打开Google Play Music。如果您有一段时间没有启动它,它将重定向到 com.google.android.music.store.ConfigContentProvider 并触发 SecurityException。这有点问题,但至少我可以告诉我的用户该怎么做。如果您能想出更好的办法,请告诉我。
提交错误也可能是个好主意。
关于java - 安全异常 : Permission Denial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43333181/