码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-07-07 16:27:17      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:ext   har   ring   echo   分享图片   mod   androi   share   param   



/** 
     * 分享功能 
     *  
     * @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));  
    }  
简单,直接使用!

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

标签:ext   har   ring   echo   分享图片   mod   androi   share   param   

原文地址:http://www.cnblogs.com/jzdwajue/p/7132566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!