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

分享文本信息

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);
声明:原创文章,版权所有,转载请注明出处,https://litets.com。