Android调用系统自带的分享功能

栏目: IOS · Android · 发布时间: 7年前

分享文本信息

Intent textIntent = new Intent(Intent.ACTION_SEND);
 textIntent.setType("text/plain");
 textIntent.putExtra(Intent.EXTRA_TEXT, "这是一段分享的文字");
 startActivity(Intent.createChooser(textIntent, "分享"));

分享单张图片

String path = getResourcesUri(R.drawable.share);
Intent imageIntent = new Intent(Intent.ACTION_SEND);
imageIntent.setType("image/jpeg");
imageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
startActivity(Intent.createChooser(imageIntent, "分享"));

分享多个文件

List<Uri> imageUris = new ArrayList<>();
Uri uri1 = Uri.parse(getResourcesUri(R.drawable.share1));
Uri uri2 = Uri.parse(getResourcesUri(R.drawable.share2));
imageUris.add(uri1);
imageUris.add(uri2);
Intent mulIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
mulIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
mulIntent.setType("image/jpeg");
startActivity(Intent.createChooser(mulIntent,"多文件分享"));

指定分享到微信

Intent intent = new Intent(Intent.ACTION_SEND);
// 分享到QQ package:com.tencent.mobileqq
intent.setPackage("com.tencent.mm");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "分享到微信的内容");
startActivity(wechatIntent);

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Programming Amazon Web Services

Programming Amazon Web Services

James Murty / O'Reilly Media / 2008-3-25 / USD 49.99

Building on the success of its storefront and fulfillment services, Amazon now allows businesses to "rent" computing power, data storage and bandwidth on its vast network platform. This book demonstra......一起来看看 《Programming Amazon Web Services》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试