Android呼叫系統自帶的分享功能
摘要:
分享文字資訊
Intent textIntent = new Intent(Intent.ACTION_SEND);
textIntent.setType("text/plain");
textIntent.putExtra(Intent.EXTRA_TEXT, ...
分享文字資訊
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);