2***@qq.com
2***@qq.com
  • 发布:2020-12-02 10:31
  • 更新:2020-12-02 10:31
  • 阅读:404

android 离线打包 分享多图失败解决方案

分类:uni-app

uniapp直接调用安卓自定义方法

class

public class share {  
  
    public void allShare(Activity context, String[] array) throws FileNotFoundException {  
  
        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {  
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();  
            StrictMode.setVmPolicy(builder.build());  
            builder.detectFileUriExposure();  
        }  
  
        ArrayList<Uri> uriList = new ArrayList<>();  
        //array为要分享图片的本地地址  
        for (int i = 0; i < array.length; i++) {  
            //将所有的本地地址转换为Uri并添加至集合  
            if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {  
                uriList.add(Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), new File(array[i]).getAbsolutePath(), "文件别名", null)));  
            }else{  
                uriList.add(Uri.parse(array[i]));  
            }  
        }  
        Intent shareIntent = new Intent();  
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);  
        //指定分享的类型  
        shareIntent.setType("image/*");  
        //打开分享界面的Action  
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);  
        //分享传递的数据  
        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);  
        //打开分享  
        context.startActivity(Intent.createChooser(shareIntent, "分享到"));  
    }  
  
}

调用方法

  
本地文件路径数组 = 【"/storage/emulated/0/Android/data/xxxxxxxx/Screenshot_XXXXXX.jpg",】  
  
let share = plus.android.importClass('你的应用包名.share');    
new share().allShare(plus.android.runtimeMainActivity(),本地文件路径数组);
2020-12-02 10:31 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复