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(),本地文件路径数组);
0 个回复