Android7.0以前获取本地文件uri用的Uri.fromFile(new File(filePath)); 后会得到一个file://,这种方式呢7.0及以后的系统版本就用不了,且会报一个异常:
android.os.FileUriExposedException
file:///storage/emulated/0/Android/data/com.alex.demo/cache/.tmp/show.mp4 exposed beyond app through Intent.getData()
举个例子:
String filePath = "/storage/emulated/0/Android/data/com.alex.demo/cache/.temp.jpg";
Uri uri = Uri.fromFile(new File(filePath));
这个uri打印出来就是"file:///storage/emulated/0/Android/data/com.alex.demo/cache/.temp.jpg"
Android7.0及以上系统版本由于共享文件权限的限制,方法不一样了,需要用FileProvider.getUriForFile()
举个例子:
String filePath = "/storage/emulated/0/Android/data/com.alex.demo/cache/.temp.jpg";
Uri uri = FileProvider.getUriForFile(BaseApplication.getApplication(), BaseApplication.getApplication().getPackageName() + ".FileProvider", new F