Android 一键分享功能简单实现
来源:互联网 发布:怎么ping电脑端口号 编辑:程序博客网 时间:2024/05/21 18:45
最近小编做了一些分享功能,需要把一些文字、图片、文件等分享出去。于是总结了一些代码,做了个助手类,实现了上述功能,以供看客老爷们拿去参考。废话不多说,直接上代码:
import java.io.File;import java.util.ArrayList;import java.util.List;import android.content.Context;import android.content.Intent;import android.net.Uri;public class ShareManager {//分享文件 public static void shareFiles(Context context, List fileList) { if(context == null || fileList == null || fileList.size() < 1) { return; } ArrayList uriList = new ArrayList(); for(File file : fileList) { Uri uri = Uri.fromFile(file); uriList.add(uri); } Intent intent = null; boolean isMultiple = uriList.size() > 1; if(isMultiple) { intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("**"); intent.putExtra(Intent.EXTRA_STREAM, uriList.get(0)); } context.startActivity(Intent.createChooser(intent, "Choose a channel to share your files...")); } //分享图片 public static void shareImage(Context context, File imageFile) { if(context == null || imageFile == null) { return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/*"); Uri uri = Uri.fromFile(imageFile); intent.putExtra(Intent.EXTRA_STREAM, uri); context.startActivity(Intent.createChooser(intent, "Choose a channel to share your image...")); } //分享文字 public static void shareText(Context context, String text) { if(context == null || text == null) { return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, text); context.startActivity(Intent.createChooser(intent, "Choose a channel to share your text...")); }}
0 0
- Android 一键分享功能简单实现
- Android中实现一键分享功能
- android一键分享功能部分实现
- Android 一键分享功能
- Android 一键分享功能
- Android:分享功能实现(超简单)
- android 实现分享功能
- android实现分享功能
- android 实现分享功能
- android 实现分享功能
- android 实现分享功能
- android 实现分享功能
- android实现分享功能
- Android 一键分享功能开发教程
- android利用Intent.ACTION_SEND实现简单分享功能
- 【Android】倒计时功能简单实现及日期工具类分享
- Android中实现一个简单的分享功能
- android简单的分享功能
- iOS开发中,如何合理地制造“BUG”并且查找BUG
- SVN常用命令
- IIS服务器代替VS自带的服务器
- 使用简洁的 Navigation Timing API 测试网页加载速度(不完全译文)
- 如何监听textview 状态的变化。。。textview被更改的变化
- Android 一键分享功能简单实现
- AFNetworking 学习
- 这个是不是安全的博客~
- 断点续传
- oracle 子查询
- smali语法总结
- Objective-C 类属性和方法的访问权限
- 如何把图片转换为PDF文档
- HDU 4786 生成树