package com.tejia.lijin.app.util.share;
|
|
import android.content.ComponentName;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.net.Uri;
|
import android.os.Build;
|
import android.widget.Toast;
|
|
import java.util.ArrayList;
|
|
public class ShareImageUtil {
|
/**
|
* 根据intent分享图片
|
*
|
* @param context
|
* @param imageList
|
* @param packageName
|
* @param activityName
|
*/
|
private static void sharePictureByIntent(Context context, ArrayList<Uri> imageList, String packageName, String activityName) {
|
Intent intent = new Intent();
|
ComponentName comp = new ComponentName(packageName, activityName);
|
intent.setComponent(comp);
|
intent.setType("image/*");
|
if (imageList.size() == 1) {
|
intent.putExtra(Intent.EXTRA_STREAM, imageList.get(0));
|
intent.setAction(Intent.ACTION_SEND);
|
} else {
|
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageList);
|
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
|
}
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.putExtra(String.valueOf(Intent.CONTENTS_FILE_DESCRIPTOR), "banli");
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);//增加读写权限
|
}
|
context.startActivity(intent);
|
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
// context.startActivity(Intent.createChooser(intent, "分享到:"));
|
}
|
|
|
/**
|
* 采用intent的方式分享到微信好友
|
*
|
* @param imageList
|
*/
|
public static void shareWXPictureByIntent(Context context, ArrayList<Uri> imageList) {
|
try {
|
sharePictureByIntent(context, imageList, "com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
|
} catch (Exception e) {
|
Toast.makeText(context, "尚未安装微信", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
|
/**
|
* 分享到微信朋友圈
|
*
|
* @param context
|
* @param imageList
|
*/
|
public static void shareWXCirclePictureByIntent(Context context, ArrayList<Uri> imageList) {
|
ArrayList<Uri> tempList = new ArrayList<>();
|
|
if (imageList.size() > 0)
|
tempList.add(imageList.get(0));
|
try {
|
sharePictureByIntent(context, tempList, "com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");
|
} catch (Exception e) {
|
Toast.makeText(context, "尚未安装微信", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
|
/**
|
* 分享到QQ
|
*
|
* @param context
|
* @param imageList
|
*/
|
public static void shareQQPictureByIntent(Context context, ArrayList<Uri> imageList) {
|
try {
|
sharePictureByIntent(context, imageList, "com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
|
} catch (Exception e) {
|
Toast.makeText(context, "尚未安装QQ", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
|
public static void shareQQZonePictureByIntent(Context context, ArrayList<Uri> imageList) {
|
try {
|
sharePictureByIntent(context, imageList, "com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
|
} catch (Exception e) {
|
Toast.makeText(context, "尚未安装QQ", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
|
/**
|
* 分享到新浪图片
|
*
|
* @param context
|
* @param imageList
|
*/
|
public static void shareSinaPictureByIntent(Context context, ArrayList<Uri> imageList) {
|
try {
|
sharePictureByIntent(context, imageList, "com.sina.weibo", "com.sina.weibo.sdk.web.WeiboSdkWebActivity");
|
} catch (Exception e) {
|
Toast.makeText(context, "尚未安装微博", Toast.LENGTH_SHORT).show();
|
}
|
}
|
}
|