Android 调用系统分享(不使用第三方),指定QQ、微信等
2017-10-16 09:57
666 查看
分享文本信息
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即可,方法可以查看以下文章戳这里查看
相关文章推荐
- [Android]不经过第三方SDK直接调用系统自带分享QQ、微信
- Android不经过第三方\官方SDK直接使用Intent快捷实现QQ微信分享
- Android使用官方API分享内容到QQ和微信(非第三方集成)
- Android使用系统方法实现分享到QQ和微信!
- Android 使用shareSDK分享(快捷分享和分享到指定平台)(微信,qq,微博)
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- [置顶] Android使用友盟集成QQ、微信、微博等第三方分享
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
- Android使用ShareSDK集成QQ、微信、微博等第三方分享
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
- Android使用友盟集成QQ、微信、微博等第三方分享与登录方法详解
- Android-将View转换成图片分享到QQ,微信(不使用第三方API)
- 使用ShareSDK完成第三方(QQ、微信、微博)登录和分享
- Android调用系统分享功能以及createChooser的使用
- 最详细Android集成QQ,微信,微博分享(不用第三方)
- Android使用shareSDK第三方登录(qq,微信,微博)
- Android调用系统分享直接抵达微信
- 最新Android实现分享到QQ QZone 博客功能(集成官方SDK,不使用第三方)
- 史上最详细Android集成QQ,微信,微博分享(不用第三方)持续更新中