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));

}

最新文章

  1. Webstorm编译TypeScript
  2. inline--行内元素
  3. pm2.5检测统计
  4. Git 的 .gitignore 配置
  5. 清除SQL Server执行计划
  6. 从零学习IOS-VirtualBox-4.3.20-96997-Win
  7. python瓦登尔湖词频统计
  8. Quartz2D使用
  9. Matlab.NET混合编程技巧之——直接调用Matlab内置函数(附源码)
  10. jquery学习笔记3——jq HTML
  11. HttpClient(一)HttpClient抓取网页基本信息
  12. 谨慎修改Python的类属性
  13. 空指针null
  14. 【托业】【新托业TOEIC新题型真题】学习笔记12-题库八-P7
  15. python模块(3)
  16. json2.js 序列化 和反序列化 转
  17. Mybatis标签bind用法
  18. js备忘录4
  19. 选择适用才最好 盘点MySQL备份方式
  20. 20145226夏艺华 《Java程序设计》实验报告三

热门文章

  1. python利用unittest进行测试用例执行的几种方式
  2. Django之环境搭建
  3. SQL索引未使用
  4. leetcode 刷题
  5. Flask的数据库连接池 DBUtils
  6. Linux系统优化实现高并发
  7. jQuery插件实例二:年华时代插件ReturnTop回到首页
  8. Centos7 apache2.4.29(httpd) 安装
  9. 【转】爬虫的一般方法、异步、并发与框架scrapy的效率比较
  10. scrapy爬虫框架之Xpath选择器