| 
 | 
 
重新封装调用系统分享文件 开源  由于官方的失效 
 
 
不过有一个缺点.不能分享App私有缓存目录文件.具体为啥我也搞不懂 
 
 
<火山程序 类型 = "通常" 版本 = 1 /> 
 
方法 一键分享文件 <公开 
        @java.导入 = "android.content.Intent\nandroid.net.Uri\nandroid.os.Bundle\njava.io.File\nandroid.os.StrictMode" 
        @安卓.权限需求 = "android.permission.WRITE_EXTERNAL_STORAGE"> 
参数 欲窗口 <类型 = 安卓窗口> 
参数 文件路径 <类型 = 文本型> 
参数 分享标题 <类型 = 文本型 注释 = "分享窗口标题" @默认值 = "测试分享文件"> 
参数 文件类型 <类型 = 文本型 @默认值 = "*/*"> 
{ 
    @ String filePath = @<文件路径>; 
    @ File file = new File(filePath); 
    @ Uri fileUri = Uri.fromFile(file); 
    @ StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); 
    @ StrictMode.setVmPolicy(builder.build()); 
    @ Intent intent = new Intent(Intent.ACTION_SEND); 
    @ intent.setType(@<文件类型>); 
    @ intent.putExtra(Intent.EXTRA_STREAM, fileUri); 
    @ @<欲窗口>.startActivity(Intent.createChooser(intent, @<分享标题>)); 
 
 
} 
 
 
 
 
 
 
 
 
 
 |   
 
 
 
 |