1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| public class Uposter {
public static void shareWeChatFriend(Activity context, String path) { new Thread(() -> { Uri uri = FileProvider.getUriForFile(context.getApplicationContext(), context.getPackageName() + ".provider", new File(path));
Intent shareIntent = new Intent(); ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI"); shareIntent.setComponent(comp); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/jpeg"); context.startActivity(Intent.createChooser(shareIntent, "分享图片")); }).start(); }
public static void shareToQQFriend(Activity context, String path) { new Thread(() -> { Tencent tencent = Tencent.createInstance(QQ_APP_ID, context); Bundle shareParams = new Bundle(); shareParams.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE); shareParams.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, path); shareParams.putString(QQShare.SHARE_TO_QQ_APP_NAME, context.getResources().getString(R.string.app_name)); shareParams.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE); tencent.shareToQQ(context, shareParams, null); }).start(); }
public static void shareToWeiboFriend(Activity context, String path) {
new Thread(() -> { Intent intent = new Intent(); intent.setPackage("com.sina.weibo"); intent.setAction(Intent.ACTION_SEND); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = FileProvider.getUriForFile(context.getApplicationContext(), context.getPackageName() + ".provider", new File(path)); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setType("image/*"); context.startActivity(Intent.createChooser(intent, "分享")); }).start(); }
public static void saveImage(Activity context, String path) { class SingleMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient {
private MediaScannerConnection mMs; private File mFile; private Context mContext;
private SingleMediaScanner(Context context, File f) { mFile = f; mContext = context; mMs = new MediaScannerConnection(context, this); mMs.connect(); }
public void onMediaScannerConnected() { mMs.scanFile(mFile.getAbsolutePath(), null); }
public void onScanCompleted(String path, Uri uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); mContext.startActivity(intent); mMs.disconnect(); }
} View v = context.findViewById(android.R.id.content); Snackbar snackbar = Snackbar.make(v, "保存成功", Snackbar.LENGTH_LONG); snackbar.setAction("点击查看", v1 -> { new SingleMediaScanner(context, new File(path)); }); snackbar.show(); }
private static void showGallery(Context context) { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"))); } }
|