先上代码:
public void callSystemShare(String imgUrl) {
Intent intent = new Intent();
/*
* //微信手动发朋友圈的界面
intent.setComponent(new ComponentName("com.tencent.mm",
"com.tencent.mm.ui.tools.ShareScreenToTimeLineUI"));
*/
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = getImageContentUri(this, new File(imgUrl));
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
} else {
uri = Uri.fromFile(new File(imgUrl));
}
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
this.startActivity(Intent.createChooser(intent, ""));
}
private Uri getImageContentUri(Context context, File imageFile) {
String filePath = imageFile.getAbsolutePath();
Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.Media._ID}, MediaStore.Images.Media.DATA + "=? ",
new String[]{filePath}, null);
Uri uri = null;
if (cursor != null) {
if (cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
Uri baseUri = Uri.parse("content://media/external/images/media");
uri = Uri.withAppendedPath(baseUri, "" + id);
}
cursor.close();
}
if (uri == null) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}
return uri;
思路:分享n张图片,先将n-1张图片添加到相册,然后带1张图片跳转到微信手动发朋友圈的界面,提示用户去相册选取。
demo 链接
网友评论