友盟分享
1,添加依賴
//友盟分享 compile files('libs/libammsdk.jar') compile files('libs/open_sdk_r5778_lite.jar') compile files('libs/SocialSDK_QQ_Full.jar') compile files('libs/SocialSDK_WeiXin_Full.jar') compile files('libs/umeng_shareboard_widget.jar') compile files('libs/umeng_social_api.jar') compile files('libs/umeng_social_net.jar') compile files('libs/umeng_social_shareboard.jar') compile files('libs/umeng_social_tool.jar'), 2,添加資源3,把封裝的類考進來
ShareUtil
4,初始化
private void initShareInfo() {Config.DEBUG = true;UMShareAPI.get(this);//微信 wx4d5fa990e9695e89, 51c6b225fa101486f6829bf55af46970 PlatformConfig.setWeixin("wx4d5fa990e9695e89", "51c6b225fa101486f6829bf55af46970");//QQ 1106623962, z5VcAfXdjOQ7T25y PlatformConfig.setQQZone("1106623962", "z5VcAfXdjOQ7T25y"); }5,使用
//分享 private void shareInit() {ShareUtil shareUtil = new ShareUtil(this);ShareContent shareInfo = new ShareContent();//標題 shareInfo.mTitle = "車務代辦,就上車務匠";//圖片 shareInfo.mMedia = new UMImage(this, R.drawable.ic_logo);//描述(描述必須小于20) shareInfo.mText = "別等被騙了,才想到用車務代辦!車務匠APP全國車務人都在用的代辦平臺,趕快來下載吧~~~";shareInfo.mTargetUrl = mApplication.getUserShareURL();if (mApplication.getUserShareURL() != null) {if (!mApplication.getUserShareURL().contains("recommendId")) {shareInfo.mTargetUrl = mApplication.getUserShareURL() + "?recommendId=" + mApplication.getUserInfo().getUserId();// String類型; }}shareUtil.setParam(shareInfo);shareUtil.showChoose();6,mainfest
<!-- youmeng 微信 --> <activity android:name=".wxapi.WXEntryActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:exported="true" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" /><activity android:name="com.tencent.tauth.AuthActivity" android:launchMode="singleTask" android:noHistory="true"><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="tencent1106623962" />//換成自己的</intent-filter> </activity> <activity android:name="com.tencent.connect.common.AssistActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" />最后貼出
public class ShareUtil {Context context;Activity activity;private ShareAction shareAction;private ShareContent shareInfo;private UMShareListener umSetShareListener;final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[]{SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ}; // SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE public ShareUtil(Activity activity) {this.activity = activity;context = activity;}/** * 添加分享的內容 */ public void setParam(ShareContent shareInfo) {this.shareInfo = shareInfo;}/** * 分享彈窗框 */ public void showChoose() {if (umSetShareListener == null || "".equals(umSetShareListener)) {shareAction = new ShareAction(activity).setDisplayList(displaylist).setContentList(shareInfo, shareInfo, shareInfo).setCallback(umShareListener);shareAction.open();} else {shareAction = new ShareAction(activity).setDisplayList(displaylist).setContentList(shareInfo, shareInfo, shareInfo).setCallback(umSetShareListener);shareAction.open();}}/** * 通過分享 * * @param share_media 單個分享 */ public void shareByType(SHARE_MEDIA share_media) {shareAction = new ShareAction(activity).setPlatform(share_media)//單個平臺傳入平臺 .withText(shareInfo.mText)//分享內容 .withTitle(shareInfo.mTitle).withMedia(new UMImage(activity, R.drawable.ic_logo)).withTargetUrl(shareInfo.mTargetUrl).setCallback(umShareListener);shareAction.share();}/** * /** * 分享結果監聽 */ private UMShareListener umShareListener = new UMShareListener() {@Override public void onResult(SHARE_MEDIA platform) {Log.d("plat", "platform" + platform);shareAction.close();Toast.makeText(activity, " 分享成功啦", Toast.LENGTH_SHORT).show();}@Override public void onError(SHARE_MEDIA platform, Throwable t) {shareAction.close();Toast.makeText(activity, " 分享失敗啦", Toast.LENGTH_SHORT).show();if (t != null) {Log.d("throw", "throw:" + t.getMessage());}}@Override public void onCancel(SHARE_MEDIA platform) {shareAction.close();Toast.makeText(activity, " 分享取消了", Toast.LENGTH_SHORT).show();}};public UMShareListener getUmSetShareListener() {return umSetShareListener;}public void setUmSetShareListener(UMShareListener umSetShareListener) {this.umSetShareListener = umSetShareListener;}public ShareAction getShareAction() {return shareAction;}public void setShareAction(ShareAction shareAction) {this.shareAction = shareAction;} }總結
- 上一篇: HBase权威指南【中文版】
- 下一篇: 删除git库中untracked fil