FileProvider共享文件

1.配置fileProvider


            android:name="android.support.v4.content.FileProvider"  
            android:authorities="com.php.demo.FileProvider"  
            android:exported="false"  
            android:grantUriPermissions="true">  
                             android:name="android.support.FILE_PROVIDER_PATHS"  
                android:resource="@xml/file_paths" />  
         
2.配置路径

root-path 对应DEVICE_ROOT,也就是File DEVICE_ROOT = new File("/"),即根目录,一般不需要配置。
files-path对应 content.getFileDir() 获取到的目录。
cache-path对应 content.getCacheDir() 获取到的目录
external-path对应 Environment.getExternalStorageDirectory() 指向的目录。
external-files-path对应 ContextCompat.getExternalFilesDirs() 获取到的目录。
external-cache-path对应 ContextCompat.getExternalCacheDirs() 获取到的目录。


            name="external_storage_root"
        path="." />
            name="files-path"
        path="." />
            name="cache-path"
        path="." />
   
            name="external_file_path"
        path="." />
   
            name="external_cache_path"
        path="." />
   
            name="root-path"
        path="" />
/paths>
3.配置调用先请求权限读取

File file = new File(Path);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = FileProvider.getUriForFile(context,"com.cgkc.taxqa.fileprovider",file);
intent.setDataAndType(uri, "application/pdf");
return intent;

你可能感兴趣的:(FileProvider共享文件)