Android 实现系统分享
使用手机上的程序,来分享/发送,比如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 实现系统分享的更多相关文章
- Android 调用系统分享文字、图片、文件,可直达微信、朋友圈、QQ、QQ空间、微博
原文:Android 调用系统分享文字.图片.文件,可直达微信.朋友圈.QQ.QQ空间.微博 兼容SDK 18以上的系统,直接调用系统分享功能,分享文本.图片.文件到第三方APP,如:微信.QQ.微博 ...
- android - 调用系统分享功能分享图片
step1: 编写分享代码, 将Uri的生成方式改为由FileProvider提供的临时授权路径,并且在intent中添加flag 注意:在Android7.0之后,调用系统分享,传入URI的时候可能 ...
- Android自定义系统分享面板
在Android中实现分享有一种比较方便的方式,调用系统的分享面板来分享我们的应用.最基本的实现如下: public Intent getShareIntent(){ Intent intent = ...
- Android调用系统分享功能总结
Android分享-调用系统自带的分享功能 实现分享功能的几个办法 1.调用系统的分享功能 2.通过第三方SDK,如ShareSDK,友盟等 3.自行使用各自平台的SDK,比如QQ,微信,微博各自的S ...
- Android调用系统分享功能以及createChooser的使用
工程结构 //效果图 点击测试分享 ...
- Android应用中实现系统“分享”接口
在android下各种文件管理器中,我们选择一个文件,点击分享可以看到弹出一些app供我们选择,这个是android系统分享功能,我们做的app也可以出现在这个列表中. 第一步:在Manifest.x ...
- [转]Android 学习资料分享(2015 版)
转 Android 学习资料分享(2015 版) 原文地址:http://www.jianshu.com/p/874ff12a4c01 目录[-] 我是如何自学Android,资料分享(2015 版) ...
- 我是如何自学Android,资料分享(2015 版)
自己学了两三个月的Android,最近花了一周左右的时间写了个App——Diigoer(已开源),又花了一两周时间找工作,收到了两个Offer,也算是对自己学习的一种认可吧:我刚开始学习总结的——&l ...
- Android调用系统相册和拍照的Demo
最近我在群里看到有好几个人在交流说现在网上的一些Android调用系统相册和拍照的demo都有bug,有问题,没有一个完整的.确实是,我记得一个月前,我一同学也遇到了这样的问题,在低版本的系统中没问题 ...
随机推荐
- Eclipse为不同的文件类型设置编码格式和编辑器
不知道大家遇到项目中编码格式不统一的情况没有,哈哈,我们就是,比如java的编码格式是GBK,html等编码是UTF-8,这样会导致很多问题,比如提交了一个UTF-8的java文件到SVN,会导致后端 ...
- Linux—yum使用详解
yum配置 yum的配置文件在 /etc/yum.conf 参考:https://www.cnblogs.com/yhongji/p/9384780.html yum源配置 yum源文件在 /et ...
- CodeForces - 573A (简单数论+模拟)
题意 https://vjudge.net/problem/CodeForces-573A 有n个数ai ,你可以把每个数任意次×2 或×3 ,问能否最终使得每个数相等. 思路 x2和x3只能改变数 ...
- 用Python写Verilog(非HLS)
https://blog.csdn.net/qq_32010099/article/details/81197171 前段时间玩Python的时候好奇, 既然Python这么强大, 那么能不能用Pyt ...
- Semantic 3D
Semantic 3D 这个数据级别的训练集有一个小BUG,是这个neugasse_station1_xyz_intensity_rgb.7z, 解压之后的名字是station1_xyz_intens ...
- CF1005F Berland and the Shortest Paths 最短路树计数
问题描述 LG-CF1005F 题解 由题面显然可得,所求即最短路树. 所以跑出最短路树,计数,输出方案即可. \(\mathrm{Code}\) #include<bits/stdc++.h& ...
- 设计模式-Prototype(通过复制构造函数实现自我复制)-(创建型模式)
以下代码来源: 设计模式精解-GoF 23种设计模式解析附C++实现源码 //Prototype.h #pragma once class Prototype { public: virtual ~P ...
- QFramework 学习
github地址: https://github.com/liangxiegame/QFramework 框架官网: http://qf.liangxiegame.com/ 视频教程: http:// ...
- sql server 按照字段分组 重新设置组序号
SELECT cpr.Id, cpr.CreateTime, cpr.Number FROM CarParkingRegistration cpr SELECT CONCAT(FORMAT(cpr ...
- JWT签名与验签
签名Token生产 using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; usi ...