首页 > 移动平台 > 详细

Android系统自带分享功能的实现(可同时分享文字和图片)

时间:2015-03-26 16:47:40      阅读:640      评论:0      收藏:0      [点我收藏+]
简单,不解释,直接上代码,可直接使用!

代码如下:

 

[java] view plaincopy技术分享技术分享
 
  1. /** 
  2.      * 分享功能 
  3.      *  
  4.      * @param context 
  5.      *            上下文 
  6.      * @param activityTitle 
  7.      *            Activity的名字 
  8.      * @param msgTitle 
  9.      *            消息标题 
  10.      * @param msgText 
  11.      *            消息内容 
  12.      * @param imgPath 
  13.      *            图片路径,不分享图片则传null 
  14.      */  
  15.     public void shareMsg(String activityTitle, String msgTitle, String msgText,  
  16.             String imgPath) {  
  17.         Intent intent = new Intent(Intent.ACTION_SEND);  
  18.         if (imgPath == null || imgPath.equals("")) {  
  19.             intent.setType("text/plain"); // 纯文本  
  20.         } else {  
  21.             File f = new File(imgPath);  
  22.             if (f != null && f.exists() && f.isFile()) {  
  23.                 intent.setType("image/jpg");  
  24.                 Uri u = Uri.fromFile(f);  
  25.                 intent.putExtra(Intent.EXTRA_STREAM, u);  
  26.             }  
  27.         }  
  28.         intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);  
  29.         intent.putExtra(Intent.EXTRA_TEXT, msgText);  
  30.         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  31.         startActivity(Intent.createChooser(intent, activityTitle));  
  32.     }  

Android系统自带分享功能的实现(可同时分享文字和图片)

原文:http://www.cnblogs.com/xgjblog/p/4368677.html

(1)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!