lmw
2 天以前 967492f43278adf716cb3cb39d209ad9ae59590f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.share.utils;
 
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
 
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.ShareContent;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
 
/**
 *
 */
public class ShareUtils {
 
    public static void share(Activity context, String content, String title, String tagUrl){
        final SHARE_MEDIA[] displayList = new SHARE_MEDIA[]{
                        SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA,
                        SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE
                };
        try {
            int icon = context.getResources().getIdentifier("ic_launcher", "mipmap", context.getPackageName());
            UMImage image = new UMImage(context, icon);
            UMWeb web = new UMWeb(tagUrl,title,content,image);
            ShareContent shareContent = new ShareContent();
            shareContent.mMedia = web;
            new ShareAction(context).setDisplayList( displayList )
                    .setShareContent(shareContent)
                    .open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void share(Activity context, String content, String title, String tagUrl, UMImage image, UMShareListener listener){
        final SHARE_MEDIA[] displayList = new SHARE_MEDIA[]{
                        SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA,
                        SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE
                };
        UMWeb web = new UMWeb(tagUrl,title,content,image);
        ShareContent shareContent = new ShareContent();
        shareContent.mMedia = web;
        new ShareAction(context).setDisplayList( displayList )
                .setShareContent(shareContent)
                .setCallback(listener)
                .open();
    }
 
    public static void share(Activity context, SHARE_MEDIA platform,String content, String title, String tagUrl,UMShareListener listener,String phone){
        share( context,  platform, content,  title,  tagUrl, null,listener,phone);
    }
    public static void share(Activity context, SHARE_MEDIA platform,String content, String title, String tagUrl, UMImage image,UMShareListener listener,String phone){
        if (platform == SHARE_MEDIA.MORE){
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+phone)); //发送指定联系人
//            Intent intent = new Intent(Intent.ACTION_VIEW); //发送页面,无联系人
//            intent.setType("vnd.android-dir/mms-sms");
            intent.putExtra("sms_body",content+tagUrl);
            context.startActivity(intent);
        }else
            try {
            int icon = context.getResources().getIdentifier("ic_launcher","mipmap",context.getPackageName());
            if (image == null) {
 
                image = new UMImage(context, icon);
            }
            UMWeb web = new UMWeb(tagUrl,title,content,image);
            ShareContent shareContent = new ShareContent();
            shareContent.mMedia = web;
            new ShareAction(context).setPlatform(platform)
                    .setShareContent(shareContent)
                    .setCallback(listener)
                    .share();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}