java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED on KitKat only

前端 未结 2 437
野性不改
野性不改 2020-11-30 04:54

I am using the DownloadManager to download images off our server and I am placing the files in the externalFilesDir.

I am send out a broadc

2条回答
  •  甜味超标
    2020-11-30 05:51

    I know it's late but try this, it works in every version:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        Uri contentUri = Uri.fromFile(out); // out is your output file
        mediaScanIntent.setData(contentUri);
        this.sendBroadcast(mediaScanIntent);
    } else {
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    }
    

提交回复
热议问题