Android 调用系统分享(不使用第三方),指定QQ、微信等

分享文本信息

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,"This is a text");
startActivity(Intent.createChooser(intent,"Share"));

分享单张图片

String path = Environment.getExternalStorageDirectory() + File.separator;//sd根目录
File file = new File(path, "test" + ".png");//这里test.png是sd卡根目录下的一个图片文件
Uri imageUri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent, "Share"));

分享视频

String path = Environment.getExternalStorageDirectory() + File.separator;//sd根目录
File file = new File(path, "test" + ".mp4");
Uri audioUri = Uri.fromFile(file);
ComponentName comp = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
Intent shareIntent = new Intent();
shareIntent.setComponent(comp);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, audioUri);
shareIntent.setType("audio/*");
startActivity(Intent.createChooser(shareIntent, "分享视频"));

分享多个文件

String path = Environment.getExternalStorageDirectory() + File.separator;//sd根目录

ArrayList<Uri> imageUris = new ArrayList<>();
File file = new File(path, "test" + ".png");
File file2 = new File(path, "test2" + ".png");
Uri imageUri = Uri.fromFile(file);
Uri imageUri2 = Uri.fromFile(file2);
imageUris.add(imageUri);
imageUris.add(imageUri2);

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);
startActivity(Intent.createChooser(intent, "Share"));

指定分享到微信朋友

ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
Intent shareIntent = new Intent();
shareIntent.setComponent(comp);            
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享多张图片"));

指定分享到微信朋友圈

ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");
Intent shareIntent = new Intent();
shareIntent.setComponent(comp);
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);   
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享多张图片"));

指定分享到QQ好友

ComponentName comp = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
Intent shareIntent = new Intent();
shareIntent.setComponent(comp);
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);  
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享多张图片"));

视频指定分享到QQ空间

String path = Environment.getExternalStorageDirectory() + File.separator;//sd根目录
File file = new File(path, "test" + ".mp4");
Uri audioUri = Uri.fromFile(file);
ComponentName comp = new ComponentName("com.qzone", "com.qzonex.module.maxvideo.activity.QzonePublishVideoActivity");
Intent shareIntent = new Intent();
shareIntent.setComponent(comp);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, audioUri);
shareIntent.setType("video/*");
startActivity(Intent.createChooser(shareIntent, "分享视频"));

分享到指定程序

只要获得包名和相应Activity即可,方法可以查看以下文章

戳这里查看

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值