Android实现分享图片和文字的功能

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

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>  
时间: 2024-12-15 14:51:50

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

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

按照官方的流程走了一遍,一切顺利,分享成功了,本来以为可以大功告成了,结果睡了一觉,第二天要给客户演示了,才发现TMD坑爹了,不能分享了,第三方的分享栏弹不出来了,我一阵惊慌,还好很快找到了解决办法:原因是我进行了代码混淆,但是没有对新添加的这部分分享到微信的代码进行处理,所以...解决问题的办法很简单:需要在混淆配置文件proguard.cfg中,增加如下两行代码: -keep class com.tencent.mm.sdk.openapi.WXMediaMessage { *;} -kee

android 使用Intent.ACTION_SEND分享图片和文字内容(新浪微博,短信等)

下面的方法只能实现普通的文字分享: 1 2 3 4 5 6 7 8 9 10 11 private void shareContent() {         Intent share = new Intent(android.content.Intent.ACTION_SEND);         share.setType("text/plain");         String title = "标题";         String extraText=&

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

1.使用html.fromHtml 2.新建ImageGetter 3.使用<img src>标签 demo: 1.设置文字 ((TextView) findViewById(R.id.tv_gradlist_calorie_desc)).setText(Html .fromHtml(descString(), getImageGetterInstance(), null)); 2.获取文字 /** * 字符串 * * @return */ private String descString(

android 调用系统分享图片及文字

调用系统分享文字:public static void shareText(Context context, String extraText) {Intent intent = new Intent(Intent.ACTION_SEND);intent.setType("text/plain");intent.putExtra(Intent.EXTRA_SUBJECT, "连接分享");intent.putExtra(Intent.EXTRA_TEXT, extr

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

android 系统的分享功能 private void share(String content, Uri uri){ Intent shareIntent = new Intent(Intent.ACTION_SEND); if(uri!=null){ //uri 是图片的地址 shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/*"); //当用户选择短信时使用sms_body取得文

Android应用程序中分享图片和文字给好友

插件地址:点此下载插件包[Unitypackage格式] 配置文件中需要添加读写sdcard的权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> using UnityEngine; using System.Collections; using System.IO; public class Share : MonoBehaviour { public static

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

private void share(String content, Uri uri){ Intent shareIntent = new Intent(Intent.ACTION_SEND); if(uri!=null){ shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/*"); //当用户选择短信时使用sms_body取得文字 shareIntent.putExtra("

android CheckBox RadioButton 图片与文字间距问题

在使用自定义的CheckBox 或RadioButton时,自定义的图标和文字在不同的手机上显示的间距不同,有时不太好控制,下面是我自定义的CheckBox: 在Layout下的xml: <CheckBox android:id="@+id/recharge_activity_cb" style="@style/CustomCheckboxTheme" android:layout_width="wrap_content" android:

android 项目 分享图片到微信

慕课网学习项目 AlertDialog 对话框设置 http://www.cnblogs.com/tyks/p/5202812.html .9.png的编辑及使用 sdk->tools->draw9patch.bat 微信API的调用 package com.dongni.wxshare; import com.tencent.mm.sdk.modelmsg.SendMessageToWX; import com.tencent.mm.sdk.modelmsg.WXImageObject; i