为了应用的推广,我们经常看到点击分享按钮会出现,比如微博微信等应用的分享二等列表,这是如何实现的呢?这一篇将要详细的介绍。

android的实现分享是通过隐式的启动activity。

分享文本

1.action是action_send,相应的代码:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "hello world");
sendIntent.setType("text/plain");
startActivity(sendIntent);  

2.改变分享的列表标题,通过Intent.createChooser()实现的。代码如下:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "hello wrold");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));  

使用Intent.createChooser()的好处

1.首先可以改变分享列表的标题。

2.会把所有的应用列出类,即使你之前选择了默认的应用。

分享图片

1.代码如下:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file1));
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));  

2.分享图片列表

ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(imageUri1); // Add your image URIs here
imageUris.add(imageUri2);  

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));  

如何让我们的应用出现在列表里面

通过声明Intent-filter

<activity
           android:name="com.example.sharedemo.ShareActivity"
           android:label="@string/app_name" >
           <intent-filter>
               <action android:name="android.intent.action.SEND" />  

               <category android:name="android.intent.category.DEFAULT" />  

               <data android:mimeType="image/*" />
           </intent-filter>
           <intent-filter>
               <action android:name="android.intent.action.SEND" />  

               <category android:name="android.intent.category.DEFAULT" />  

               <data android:mimeType="text/plain" />
           </intent-filter>
           <intent-filter>
               <action android:name="android.intent.action.SEND_MULTIPLE" />  

               <category android:name="android.intent.category.DEFAULT" />  

               <data android:mimeType="image/*" />
           </intent-filter>
       </activity>  

Android实现分享图片和文字的功能的更多相关文章

  1. Android TextView中有图片有文字混合排列

    Android TextView中有图片有文字混合排列 1.使用html.fromHtml 2.新建ImageGetter 3.使用<img src>标签 demo: 1.设置文字 ((T ...

  2. Android微信分享图片大于32k进行压缩

    微信分享视频的时候,需要传一个图片数组,大小不能大于32k. 解决方案:使用Bitmap自带的compress方法解决了这个问题. 源码如下: <span style="font-si ...

  3. Android 巧妙实现图片和文字布局

    之前写过一个博客是关于实现图片和文字左右或者上下布局的方法, 下面是博客的主要内容: 布局文件很简单,用来展示RadioButton的使用方法. 1 <?xml version="1. ...

  4. Android 调用系统的分享[完美实现同一时候分享图片和文字]

    android 系统的分享功能 private void share(String content, Uri uri){ Intent shareIntent = new Intent(Intent. ...

  5. Android APP 分享图片文字到微信刚開始正常,后面就不弹出分享框了

    依照官方的流程走了一遍.一切顺利,分享成功了.本来以为能够大功告成了,结果睡了一觉,第二天要给客户演示了.才发现TMD坑爹了,不能分享了,第三方的分享栏弹不出来了.我一阵惊慌,还好非常快找到了解决的方 ...

  6. 完美实现同时分享图片和文字(Intent.ACTION_SEND)

    private void share(String content, Uri uri){ Intent shareIntent = new Intent(Intent.ACTION_SEND); if ...

  7. Android 巧妙实现图片和文字上下布局或者左右布局

    最近去了一家新公司,然后开始做新的项目,看其代码发现了一个很巧妙的方法来实现图片在上面文字在下面的布局方式.只需要一个控件——RadioButton. 布局文件很简单,用来展示RadioBUtton的 ...

  8. 用百度AI的OCR文字识别结合JAVA实现了图片的文字识别功能

    第一步可定要获取百度的三个东西 要到百度AI网站(http://ai.baidu.com/)去注册 然后获得 -const APP_ID = '请填写你的appid'; -const API_KEY ...

  9. Android 微信分享图片

    "; //微信 APPID private IWXAPI iwxapi; private void regToWx() { iwxapi = WXAPIFactory.createWXAPI ...

随机推荐

  1. [SHOI2008]cactus仙人掌图

    [题目描述] 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回路. 举例 ...

  2. [HNOI2006]公路修建问题

    题目描述 输入输出格式 输入格式: 在实际评测时,将只会有m-1行公路 输出格式: 输入输出样例 输入样例#1: 复制 4 2 5 1 2 6 5 1 3 3 1 2 3 9 4 2 4 6 1 3 ...

  3. ●Joyoi Dotp 驱逐猪猡

    题链: http://www.joyoi.cn/problem/tyvj-2610题解: 期望dp,高斯消元 对于每一种到达i点的方案,都存在一个概率p, 令dp[i]表示到达i点的期望次数,那么容易 ...

  4. ●BZOJ 1076 [SCOI2008]奖励关

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1076题解: 期望dp. (模糊的题意,2333) 题中的:"现在决定不吃的宝物以后 ...

  5. hihocoder——1041国庆出游(搜索)

    描述 小Hi和小Ho准备国庆期间去A国旅游.A国的城际交通比较有特色:它共有n座城市(编号1-n):城市之间恰好有n-1条公路相连,形成一个树形公路网.小Hi计划从A国首都(1号城市)出发,自驾遍历所 ...

  6. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  7. C语言程序设计第五次作业--循环结构(1)

    (一)改错题 输出华氏摄氏温度转换表:输入两个整数lower和upper,输出一张华氏摄氏温度转换表,华氏温度的取值范围是{lower,upper},每次增加2℉.计算公式如下: c = 5×(f-3 ...

  8. C语言预备作业

    一.关于师生关系 第一种:我认为师生关系不是仅仅的餐馆与食客的关系,因为食客可以给餐馆评分,也可以选择是否继续在这里吃,但是学生却不可以选择老师,因为老师是传授知识的,无法由自己来选择.而学生是需要完 ...

  9. Debugging TensorFlow models 调试 TensorFlow 模型

    Debugging TensorFlow models Symbolic nature of TensorFlow makes it relatively more difficult to debu ...

  10. Mysql优化--慢查询日志

    Mysql 系列文章主页 =============== 默认没有开启慢查询日志功能.如果不是调优需要的话,一般不建议开启. 查看是否开启慢查询日志: SHOW VARIABLES LIKE '%sl ...