参考Android7.0须知–应用间共享文件(FileProvider)
注意:修改targetSdkVersion还是会报错,不像之前的权限控制,改成23以下就能兼容M的权限
在Android N上,文件共享需要使用FileProvider共享文件。FileProvider在support中,向下兼容
例子:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri photoURI = FileProvider.getUriForFile(this,
BuildConfig.APPLICATION_ID + ".fileprovider",
new File(mCurrentPhotoPath));
intent.setDataAndType(photoURI, "image/*");
startActivity(intent);
Demo源码
Demo中包含使用PermissionsDispatcher申请权限,打开相机,打开相册,压缩图片,使用第三方打开图片的功能