今天新入手一台安卓设备调试程序,结果把发现以前好用的程序装上报错了:
09-22 12:08:46.881: E/AndroidRuntime(23911): java.lang.RuntimeException: Unable to start activity ComponentInfo{coms.itjhb.player/com.itjhb.player.activity.PlayActivity}: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=23911, uid=10089
因为播放器会扫描新加入歌曲,所以在监听这个broadcast。 在stackoverflow找到了问题所在:4.4.2 kitkat版本保护了这个广播 android.intent.action.MEDIA_MOUNTED
<protected-broadcast android:name="android.intent.action.MEDIA_MOUNTED" />
bug源于代码
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
讲上述替换为
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mediaMountUri));
问题修复。