Android 使用系统自带分享功能
way1:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");// setType("audio/*");
intent.putExtra(Intent.EXTRA_SUBJECT, "share");
intent.putExtra(Intent.EXTRA_TEXT, "test http://www.qq.com/ 测试");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, getTitle()));
way2:
bgimg0 = getImageFromAssetsFile("Cat_Blink/cat_blink0000.png");
/**
* 从Assets中读取图片
*/
private Bitmap getImageFromAssetsFile(String fileName)
{
Bitmap image = null;
AssetManager am = getResources().getAssets();
try
{
InputStream is = am.open(fileName);
image = BitmapFactory.decodeStream(is);
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return image;
}
上面的代码是从assets中获取图片的代码,下面的代码是分享图片的代码:
/**
* 分享功能
*
* @param context
* 上下文
* @param activityTitle
* Activity的名字
* @param msgTitle
* 消息标题
* @param msgText
* 消息内容
* @param imgPath
* 图片路径,不分享图片则传null
*/
public void shareMsg(String activityTitle, String msgTitle, String msgText,
String imgPath) {
Intent intent = new Intent(Intent.ACTION_SEND);
if (imgPath == null || imgPath.equals("")) {
intent.setType("text/plain"); // 纯文本
} else {
File f = new File(imgPath);
if (f != null && f.exists() && f.isFile()) {
intent.setType("image/jpg");
Uri u = Uri.fromFile(f);
intent.putExtra(Intent.EXTRA_STREAM, u);
}
}
intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
intent.putExtra(Intent.EXTRA_TEXT, msgText);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, activityTitle));
}
最新文章
- Webstorm编译TypeScript
- inline--行内元素
- pm2.5检测统计
- Git 的 .gitignore 配置
- 清除SQL Server执行计划
- 从零学习IOS-VirtualBox-4.3.20-96997-Win
- python瓦登尔湖词频统计
- Quartz2D使用
- Matlab.NET混合编程技巧之——直接调用Matlab内置函数(附源码)
- jquery学习笔记3——jq HTML
- HttpClient(一)HttpClient抓取网页基本信息
- 谨慎修改Python的类属性
- 空指针null
- 【托业】【新托业TOEIC新题型真题】学习笔记12-题库八-P7
- python模块(3)
- json2.js 序列化 和反序列化 转
- Mybatis标签bind用法
- js备忘录4
- 选择适用才最好 盘点MySQL备份方式
- 20145226夏艺华 《Java程序设计》实验报告三