使用手机上的程序,来分享/发送,比如QQ的“发送到我的电脑”。

1、分享/发送文本内容

  Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
//要分享的文本内容,选择某项后会直接把这段文本发送出去,相当于调用选中的应用的接口,并传参
shareIntent.putExtra(Intent.EXTRA_TEXT, "Here is the Shared text.");
//需要使用Intent.createChooser,这里我们直接复用。第二个参数并不会显示出来
shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
startActivity(shareIntent);

通用步骤:

首先将Intent的cation设置为Intent.ACTION_SEND,

其次根据分享的内容设置不同的Type,

然后根据不同的社交平台设置相关Extras,

最后创建并启动选择器

2、分享/发送单张图片

  //指定要分享的图片路径
Uri imgUri = Uri.parse("mnt/sdcard/1.jpg");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
shareIntent.setType("image/*");
shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
startActivity(shareIntent);

注意根目录为     mnt/sdcard/

3、分享/发送多张图片

  Uri imgUri1 = Uri.parse("mnt/sdcard/1.jpg");
Uri imgUri2 = Uri.parse("mnt/sdcard/2.jpg");
ArrayList<Uri> imgUris = new ArrayList<Uri>(); //使用集合保存
imgUris.add(imgUri1);
imgUris.add(imgUri2); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); //注意是Intent_ACTION_MULTIPLE
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imgUris); //注意是方法是putParcelableArrayListExtra()
shareIntent.setType("image/*");
shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
startActivity(shareIntent);

Android 实现系统分享的更多相关文章

  1. Android 调用系统分享文字、图片、文件,可直达微信、朋友圈、QQ、QQ空间、微博

    原文:Android 调用系统分享文字.图片.文件,可直达微信.朋友圈.QQ.QQ空间.微博 兼容SDK 18以上的系统,直接调用系统分享功能,分享文本.图片.文件到第三方APP,如:微信.QQ.微博 ...

  2. android - 调用系统分享功能分享图片

    step1: 编写分享代码, 将Uri的生成方式改为由FileProvider提供的临时授权路径,并且在intent中添加flag 注意:在Android7.0之后,调用系统分享,传入URI的时候可能 ...

  3. Android自定义系统分享面板

    在Android中实现分享有一种比较方便的方式,调用系统的分享面板来分享我们的应用.最基本的实现如下: public Intent getShareIntent(){ Intent intent = ...

  4. Android调用系统分享功能总结

    Android分享-调用系统自带的分享功能 实现分享功能的几个办法 1.调用系统的分享功能 2.通过第三方SDK,如ShareSDK,友盟等 3.自行使用各自平台的SDK,比如QQ,微信,微博各自的S ...

  5. Android调用系统分享功能以及createChooser的使用

    工程结构 //效果图 点击测试分享                                                                                   ...

  6. Android应用中实现系统“分享”接口

    在android下各种文件管理器中,我们选择一个文件,点击分享可以看到弹出一些app供我们选择,这个是android系统分享功能,我们做的app也可以出现在这个列表中. 第一步:在Manifest.x ...

  7. [转]Android 学习资料分享(2015 版)

    转 Android 学习资料分享(2015 版) 原文地址:http://www.jianshu.com/p/874ff12a4c01 目录[-] 我是如何自学Android,资料分享(2015 版) ...

  8. 我是如何自学Android,资料分享(2015 版)

    自己学了两三个月的Android,最近花了一周左右的时间写了个App——Diigoer(已开源),又花了一两周时间找工作,收到了两个Offer,也算是对自己学习的一种认可吧:我刚开始学习总结的——&l ...

  9. Android调用系统相册和拍照的Demo

    最近我在群里看到有好几个人在交流说现在网上的一些Android调用系统相册和拍照的demo都有bug,有问题,没有一个完整的.确实是,我记得一个月前,我一同学也遇到了这样的问题,在低版本的系统中没问题 ...

随机推荐

  1. java 和 spring 的异步

    spring 的 async 注解 https://www.baeldung.com/spring-async@Async will make it execute in a separate thr ...

  2. July 13th, 2018. Friday, Week 28th.

    Don't let the mistakes and disappointments of the past control and direct your future. 不要让你的未来被过去的错误 ...

  3. 一套从alpine基本镜像到node8.16.2的全套dockerfile

    这个花了点时间,可以正式跑起来了. 加了常用的工具及中文时区,非root帐号. 除了pm2,其它的module放到应用程序本身的node_modules目录下来实现的. 一,3rd_part/node ...

  4. golang数据结构和算法之StackArray数组堆栈

    用数组实现的堆栈, 另一种,是用链表实现的堆栈, 在各种不同的编程语言上, 实现都是类似的. StackArray.go package StackArray //基于数组实现的堆栈 const ar ...

  5. Hive 读书札记

    把数据从一个关系型数据库直接导入 Hive,使用 Sqoop.

  6. OC方法交换swizzle详细介绍——不再有盲点

    原文链接:https://www.cnblogs.com/mddblog/p/11105450.html 如果对方法交换已经比较熟悉,可以跳过整体介绍,直接看常见问题部分 整体介绍 方法交换是runt ...

  7. 优秀文章 Swagger

    原文:https://www.cnblogs.com/peterYong/p/9569453.html 原文:https://www.cnblogs.com/lhbshg/p/8711604.html

  8. [RN] React Native 调试技巧

    React Native 调试技巧 一. 安卓模拟器调出Dev Setting 命令 adb shell input keyevent 二.图片不出来时,先运行此命令,再重新 run react-na ...

  9. 第02组 Beta冲刺(4/5)

    队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 讨论校园百科究竟如何实现,并分配了任务 提交记录(全组共用) 接下来的计划 加快校园百科的进度 准备Beta版本的汇报 还 ...

  10. python 利用cip.cc查询IP归属地

    def ipinfocip(ip): # 获得 输入框中的信息 url = "http://www.cip.cc/%s" % ip # 模拟浏览器请求网络 headers={'Us ...