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