cn.sharesdk.sina.weibo.SinaWeibo Java Examples

The following examples show how to use cn.sharesdk.sina.weibo.SinaWeibo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoginAty.java    From Huochexing12306 with Apache License 2.0 6 votes vote down vote up
/**
	 * 转为自己平台的表示
	 * @param plat
	 * @return
	 */
	private ThirdPartyPlatformInfo getThirdPartyPlatfromInfo(Platform plat) {
		Map<Integer, ThirdPartyPlatformInfo> map = TT.getPlatformInfos();
		if (QQ.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_QQ);
		}else if (SinaWeibo.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_SINA_WEIBO);
		}
//		else if (Douban.NAME.equals(plat.getName())){
//			return map.get(TT.PLATFORM_DOUBAN);
//		}
		else if (GooglePlus.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_GOOGLE_PLUS);
		}else if (Wechat.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_WECHAT);
		}else if (Yixin.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_YIXIN);
		}else if (Renren.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_RENREN);
		}else if (Line.NAME.equals(plat.getName())){
			return map.get(TT.PLATFORM_LINE);
		}else{
			return null;
		}
	}
 
Example #2
Source File: WeiboShare.java    From ShareSDK-for-Android with MIT License 6 votes vote down vote up
/**
 * 新浪linkcard分享
 **/
public void shareLinkCard() {
	JSONObject jsonObject = new JSONObject();
	try {
		jsonObject.put("url", "https://t3.ftcdn.net/jpg/02/01/25/00/240_F_201250053_xMFe9Hax6w01gOiinRLEPX0Wt1zGCzYz.jpg");
		jsonObject.put("width", 120);
		jsonObject.put("height", 120);
	} catch (JSONException e) {
		e.printStackTrace();
	}

	Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
	Platform.ShareParams sp = new Platform.ShareParams();
	sp.setText("MobSDK 只为最优质的服务");
	sp.setLcCreateAt("2019-01-24");
	sp.setLcDisplayName("Mob-全球领先的第三方服务商");
	sp.setLcImage(jsonObject);
	sp.setLcSummary("不止是SDK");
	sp.setLcUrl("http://www.mob.com/");
	sp.setLcObjectType("webpage");
	platform.setPlatformActionListener(platformActionListener);
	platform.share(sp);
}
 
Example #3
Source File: UserBean.java    From BaoKanAndroid with MIT License 6 votes vote down vote up
/**
 * 从本地更新用户信息 - 登录成功后保存到偏好设置
 */
public void updateUserInfoFromLocal() {

    // 移除第三方授权
    Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
    if (weibo.isAuthValid()) {
        weibo.removeAccount(true);
    }
    Platform qq = ShareSDK.getPlatform(QQ.NAME);
    if (qq.isAuthValid()) {
        qq.removeAccount(true);
    }

    // 内存缓存
    UserBean.userAccount = this;
    // 磁盘缓存
    encode();
}
 
Example #4
Source File: MainActivity.java    From ShareSDKShareDifMsgDemo-Android with MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.btn_sms://短信分享
		showShare(true, ShortMessage.NAME);
		break;
	case R.id.btn_sina://新浪分享
		showShare(true, SinaWeibo.NAME);			
		break;
	case R.id.btn_tencent://腾讯分享
		showShare(true, TencentWeibo.NAME);			
		break;			
	case R.id.btn_wechatmoment://朋友圈分享
		showShare(true, WechatMoments.NAME);			
		break;			
	default:
		break;
	}
}
 
Example #5
Source File: FragmentLogin.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    switch (msg.what) {
        case 0:
            Platform platform = (Platform) msg.obj;
            String platformName = "";
            if (Wechat.NAME.equals(platform.getName())) {
                platformName = "wechat";
            } else if (QZone.NAME.equals(platform.getName())) {
                platformName = "qq";
            } else if (SinaWeibo.NAME.equals(platform.getName())) {
                platformName = "sina";
            }
            checkBind(platform.getDb(), platformName);
            break;
        case 1:
            ZToastUtils.toastMessage(mContext.getApplicationContext(), getString(R.string.wechat_client_inavailable));
            break;
        case 2:
            ZToastUtils.toastMessage(mContext.getApplicationContext(), getString(R.string.v_toast_third_sso_fail));
            break;
        case 3:
            ZToastUtils.toastMessage(mContext.getApplicationContext(), getString(R.string.v_toast_third_sso_cancel));
            break;
    }
}
 
Example #6
Source File: WeiboShare.java    From ShareSDK-for-Android with MIT License 5 votes vote down vote up
public void shareImage(PlatformActionListener mListener){
	Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
	Platform.ShareParams shareParams = new  Platform.ShareParams();
	shareParams.setImageUrl(ResourcesManager.getInstace(MobSDK.getContext()).getImageUrl());
	shareParams.setImagePath(ResourcesManager.getInstace(MobSDK.getContext()).getImagePath());
	if(!DemoUtils.isValidClientSina("com.sina.weibo")){
		shareParams.setUrl(ResourcesManager.getInstace(MobSDK.getContext()).getUrl());
	}
	shareParams.setLongitude(ResourcesManager.longitude);
	shareParams.setLatitude(ResourcesManager.latitude);
	platform.setPlatformActionListener(mListener);
	platform.share(shareParams);
}
 
Example #7
Source File: WeiboShare.java    From ShareSDK-for-Android with MIT License 5 votes vote down vote up
public void shareText(PlatformActionListener mListener){
	Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
	Platform.ShareParams shareParams = new  Platform.ShareParams();
	shareParams.setText(ResourcesManager.getInstace(MobSDK.getContext()).getText());
	if(!DemoUtils.isValidClientSina("com.sina.weibo")){
		shareParams.setUrl(ResourcesManager.getInstace(MobSDK.getContext()).getUrl());
	}
	platform.setPlatformActionListener(mListener);
	platform.share(shareParams);
}
 
Example #8
Source File: WeiboShare.java    From ShareSDK-for-Android with MIT License 5 votes vote down vote up
public void shareVideo(){
	Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
	Platform.ShareParams shareParams = new  Platform.ShareParams();
	shareParams.setFilePath(ResourcesManager.getInstace(MobSDK.getContext()).getFilePath());
	shareParams.setText(ResourcesManager.getInstace(MobSDK.getContext()).getText());
	shareParams.setImageUrl(ResourcesManager.getInstace(MobSDK.getContext()).getImageUrl());
	shareParams.setShareType(Platform.SHARE_VIDEO);
	platform.setPlatformActionListener(platformActionListener);
	platform.share(shareParams);
}
 
Example #9
Source File: WeiboShare.java    From ShareSDK-for-Android with MIT License 5 votes vote down vote up
public void shareImage(){
	Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
	Platform.ShareParams shareParams = new  Platform.ShareParams();
	shareParams.setImageUrl(ResourcesManager.getInstace(MobSDK.getContext()).getImageUrl());
	shareParams.setImagePath(ResourcesManager.getInstace(MobSDK.getContext()).getImagePath());
	shareParams.setShareType(Platform.SHARE_IMAGE);
	shareParams.setLongitude(ResourcesManager.longitude);
	shareParams.setLatitude(ResourcesManager.latitude);
	platform.setPlatformActionListener(platformActionListener);
	platform.share(shareParams);
}
 
Example #10
Source File: WeiboShare.java    From ShareSDK-for-Android with MIT License 5 votes vote down vote up
public void shareText(){
	Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
	Platform.ShareParams shareParams = new  Platform.ShareParams();
	shareParams.setText(ResourcesManager.getInstace(MobSDK.getContext()).getText());
	platform.setPlatformActionListener(platformActionListener);
	platform.share(shareParams);
}
 
Example #11
Source File: FragmentLogin.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
@Override
    public void onClick(View v) {
        int vId = v.getId();
        switch (vId) {
            case R.id.tv_regist:
                mCallBack.fragmentChanged(FragmentRegist.class.getSimpleName(), null, false);
                break;
            case R.id.tv_forgetpwd:
                //TODO
//                mCallBack.fragmentChanged(FragmentForgetPwd.class.getSimpleName(), null, false);
                break;
            case R.id.iv_wechat:
                ShareSDK.initSDK(mContext);
                authorize(ShareSDK.getPlatform(Wechat.NAME), "wechat");
                break;
            case R.id.iv_qq:
                ShareSDK.initSDK(mContext);
                authorize(ShareSDK.getPlatform(QZone.NAME), "qq");
                break;
            case R.id.iv_sina:
                ShareSDK.initSDK(mContext);
                authorize(ShareSDK.getPlatform(SinaWeibo.NAME), "sina");
                break;
            case R.id.iv_close:
                getActivity().onBackPressed();
                break;
            case R.id.btn_login:
                String userName = mEt_username.getText().toString();
                String pwd = mEt_pwd.getText().toString();
                if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(pwd)) {
                    ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_name_pwd_not_null);
                    return;
                }
                login(userName, pwd);
                break;
        }
    }
 
Example #12
Source File: ShareContentCustomizeDemo.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public void onShare(Platform platform, Platform.ShareParams paramsToShare) {
        if (platform instanceof CustomPlatform) {
            return;
        }
//		int id = ShareSDK.platformNameToId(platform.getName());
//		if (MainActivity.TEST_TEXT != null && MainActivity.TEST_TEXT.containsKey(id)) {
//			String text = MainActivity.TEST_TEXT.get(id);
//			paramsToShare.setText(text);
//		} else if ("Twitter".equals(platform.getName())) {
//			// 改写twitter分享内容中的text字段,否则会超长,
//			// 因为twitter会将图片地址当作文本的一部分去计算长度
//
//			String text = platform.getContext().getString(R.string.share_content_short);
//			paramsToShare.setText(text);
//		}

        Log.e("APP", "platform.getName():" + platform.getName());

        int id = ShareSDK.platformNameToId(platform.getName());
        if (SinaWeibo.NAME.equals(platform.getName())) {
            // 改写twitter分享内容中的text字段,否则会超长,
            // 因为twitter会将图片地址当作文本的一部分去计算长度

            String title = paramsToShare.getTitle();
            String titleUrl = paramsToShare.getTitleUrl();

//            if(title!=null&&title.length())


            String text = title + " " + titleUrl + ((weiboAt != null && weiboAt.length() > 0) ? " @" + weiboAt : "");
            paramsToShare.setText(text);
            paramsToShare.setImageUrl(null);
        }
    }
 
Example #13
Source File: InitUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static void initShareSDK(Context context) {

        ShareSDK.initSDK(context, true);

        HashMap<String, Object> hashMap1 = new HashMap<String, Object>();
        hashMap1.put("Id", 1);
        hashMap1.put("Enable", ClanUtils.isUseShareSDKPlatformName(context, SinaWeibo.NAME) + "");
        ShareSDK.setPlatformDevInfo(Wechat.NAME, hashMap1);

//        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
//        hashMap3.put("Id", 6);
//        hashMap3.put("Enable", ClanUtils.isUseShareSDKPlatformName(context, QQ.NAME) + "");
//        ShareSDK.setPlatformDevInfo("QZone", hashMap3);

        HashMap<String, Object> hashMap4 = new HashMap<String, Object>();
        hashMap4.put("Id", 4);
        hashMap4.put("Enable", ClanUtils.isUseShareSDKPlatformName(context, Wechat.NAME) + "");
        ShareSDK.setPlatformDevInfo(Wechat.NAME, hashMap4);

        HashMap<String, Object> hashMap5 = new HashMap<String, Object>();
        hashMap5.put("Id", 5);
        hashMap5.put("Enable", ClanUtils.isUseShareSDKPlatformName(context, Wechat.NAME) + "");
        ShareSDK.setPlatformDevInfo(WechatMoments.NAME, hashMap5);

//        HashMap<String, Object> hashMap6 = new HashMap<String, Object>();
//        hashMap6.put("Id", 6);
//        hashMap6.put("Enable", ClanUtils.isUseShareSDKPlatformName(context, Wechat.NAME) + "");
//        ShareSDK.setPlatformDevInfo(WechatFavorite.NAME, hashMap6);

//        HashMap<String, Object> hashMap7 = new HashMap<String, Object>();
//        hashMap7.put("Id", 7);
//        hashMap7.put("Enable", ClanUtils.isUseShareSDKPlatformName(context, QQ.NAME) + "");
//        ShareSDK.setPlatformDevInfo(QQ.NAME, hashMap7);


    }
 
Example #14
Source File: LoginActivity.java    From xmpp with Apache License 2.0 5 votes vote down vote up
/**
 * 新浪微博登录
 */
private void weibo_login() {
    Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
    if (weibo.isValid()) {
        weibo.removeAccount();
    }

    weibo.setPlatformActionListener(this); // 设置分享事件回调
    weibo.SSOSetting(true); // 设置false表示使用SSO授权方式
    // weibo.authorize();
    weibo.showUser(null);

}
 
Example #15
Source File: LoginAty.java    From Huochexing12306 with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.login_btnSkip:
		startActivity(new Intent(this, MainActivity.class));
		this.finish();
		break;
	case R.id.login_btnLogin:
		// 登录验证代码
		String usernameText = "";
		String passwordText = "";
		try {
			usernameText = etUserName.getText().toString().trim();
			passwordText = etPwd.getText().toString().trim();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 检验输入是否合法
		if (!validate(usernameText, passwordText)) {
			return;
		}
		// 登录
		// 检查网络是否可用
		if (HttpUtil.isNetworkConnected(LoginAty.this)) {
			// 登录
			login(usernameText, passwordText, false);
		} else {
			showMsg("网络不可用,请检查网络状态" + SF.NO_NETWORK);
		}
		break;
	case R.id.login_btnFindPwd:
		startActivity(new Intent(this, FindPwdActivity.class));
		break;
	case R.id.login_btnUserRegister:
		startActivity(new Intent(this, RegisterActivity.class));
		break;
	case R.id.login_ivQQ:
		doThirdPartyLogin(new QQ(this));
		break;
	case R.id.login_ivSinaWeibo:
		doThirdPartyLogin(new SinaWeibo(this));
		break;
	case R.id.login_ivDouban:
		break;
	case R.id.login_ivGoogleplus:
		doThirdPartyLogin(new GooglePlus(this));
		break;
	case R.id.login_ivWeichat:
		doThirdPartyLogin(new Wechat(this));
		break;
	case R.id.login_ivYixin:
		doThirdPartyLogin(new Yixin(this));
		break;
	case R.id.login_ivRenren:
		doThirdPartyLogin(new Renren(this));
		break;
	case R.id.login_ivLine:
		doThirdPartyLogin(new Line(this));
		break;
	}
}
 
Example #16
Source File: PlatformAuthorizeUserInfoManager.java    From ShareSDK-for-Android with MIT License 4 votes vote down vote up
public void sinaAuthorize() {
	Platform sina = ShareSDK.getPlatform(SinaWeibo.NAME);
	doAuthorize(sina);
}
 
Example #17
Source File: PlatformShareManager.java    From ShareSDK-for-Android with MIT License 4 votes vote down vote up
public void shareLinkCard(String name) {
	if (name.equals(SinaWeibo.NAME)) {
		WeiboShare sinaWeibo = new WeiboShare(platformActionListener);
		sinaWeibo.shareLinkCard();
	}
}
 
Example #18
Source File: ShareSDKUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public static void share(ActionBarActivity activity, String title, String text, String comment
            , String titleUrl, String siteName, String siteUrl, String imagePath, String imageUrl, final String weiboAt) {
        ShareSDK.initSDK(activity);
        final OnekeyShare oks = new OnekeyShare();

        title = HtmlUtils.delHTMLTag(title);
        text = HtmlUtils.delHTMLTag(text);

        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
        //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle(title);
        // titleUrl是标题的网络链接,仅在人人网和QQ空间使用
        oks.setTitleUrl(titleUrl);
        // text是分享文本,所有平台都需要这个字段
        oks.setText(text);

        // imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
        if (imagePath != null && imagePath.length() > 0) {
            oks.setImagePath(imagePath);//确保SDcard下面存在此张图片
        } else
            oks.setImageUrl(imageUrl);

        // url仅在微信(包括好友和朋友圈)中使用
        oks.setUrl(titleUrl);
        // comment是我对这条分享的评论,仅在人人网和QQ空间使用
        oks.setComment(comment);
        // site是分享此内容的网站名称,仅在QQ空间使用
        oks.setSite(siteName);
        // siteUrl是分享此内容的网站地址,仅在QQ空间使用
        oks.setSiteUrl(siteUrl);


        oks.setOnShareButtonClickListener(new PlatformListFakeActivity.OnShareButtonClickListener() {
            @Override
            public void onClick(View v, List<Object> checkPlatforms) {

                ZogUtils.printLog(ShareSDKUtils.class, "v:" + v + " checkPlatforms:" + checkPlatforms + " " + checkPlatforms.size());
                if (checkPlatforms != null && !checkPlatforms.isEmpty() && (checkPlatforms.get(0) instanceof SinaWeibo)) {
//                    String shareContent = oks.getTitle() + " " + oks.getTitleUrl() + ((weiboAt != null && weiboAt.length() > 0) ? " @" + weiboAt : "");

                    String shareContent = oks.getTitle();
                    oks.setText(shareContent);

                    oks.setImageUrl(null);


                }


            }
        });
        ShareContentCustomizeDemo  shareContentCustomizeDemo =  new ShareContentCustomizeDemo();
        shareContentCustomizeDemo.setSinaWeiboAt(weiboAt);
        oks.setShareContentCustomizeCallback(shareContentCustomizeDemo);

        // 启动分享GUI
        oks.show(activity);

    }
 
Example #19
Source File: ShareUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public static SharePopupWindow showShare(Context context, View showAt, String title, String text, String imageurl, String url, PlatformActionListener platformActionListener) {
    ZogUtils.printError(ThreadDetailActivity.class, "showShare imageurl:" + imageurl);

    ArrayList<ShareItem> items = new ArrayList<>();
    if (ClanUtils.isUseShareSDKPlatformName(context, Wechat.NAME)) {
        ShareItem shareItem0 = new ShareItem(Wechat.NAME, context.getResources().getDrawable(R.drawable.sns_weixin_icon), "微信好友");
        ShareItem shareItem1 = new ShareItem(WechatMoments.NAME, context.getResources().getDrawable(R.drawable.sns_weixin_timeline_icon), "朋友圈");
        items.add(shareItem0);
        items.add(shareItem1);
    }

    if (ClanUtils.isUseShareSDKPlatformName(context, SinaWeibo.NAME)) {
        ShareItem shareItem2 = new ShareItem(SinaWeibo.NAME, context.getResources().getDrawable(R.drawable.sns_sina_icon), "新浪微博");
        items.add(shareItem2);

    }

    if (ClanUtils.isUseShareSDKPlatformName(context, "QQ")) {
        ShareItem shareItem3 = new ShareItem("QQ", context.getResources().getDrawable(R.drawable.sns_qqfriends_icon), "QQ");
        ShareItem shareItem4 = new ShareItem("QZone", context.getResources().getDrawable(R.drawable.sns_qzone_icon), "QQ空间");
        items.add(shareItem3);
        items.add(shareItem4);
    }

    ShareItem shareItem5 = new ShareItem("Copy", context.getResources().getDrawable(R.drawable.sns_copy_icon), "复制链接");
    items.add(shareItem5);

    ShareModel model = new ShareModel();
    model.setImageUrl(imageurl);
    model.setText(text);
    model.setTitle(title);
    model.setUrl(url);


    SharePopupWindow share = SharePopupWindow.init(context, items, model);
    share.setPlatformActionListener(platformActionListener);
    share.setOnItemClickListener(new ShareItemClickListener(share));
    share.showAtLocation(showAt,
            Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

    return  share;
}
 
Example #20
Source File: LoginActivity.java    From BaoKanAndroid with MIT License 4 votes vote down vote up
/**
 * 新浪登录
 */
private void sinaLogin() {
    showShareSDKLogin(SinaWeibo.NAME);
}
 
Example #21
Source File: SettingActivity.java    From AnimeTaste with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.only_for_wifi:
		break;
	case R.id.use_hd:

		break;
	case R.id.suggestion:
		Intent intent = new Intent(mContext, FeedbackActivity.class);
		startActivity(intent);
		break;
	case R.id.recommend:
		Intent shareIntent = new Intent(Intent.ACTION_SEND);
		shareIntent.setType("text/plain");
		shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
				getText(R.string.share_title));
		shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
				getText(R.string.share_app_body));
		startActivity(Intent.createChooser(shareIntent,
				getText(R.string.share_via)));
		break;
	case R.id.focus_us:
		mWeibo = new SinaWeibo(mContext);
		mWeibo.setPlatformActionListener(this);
		mWeibo.authorize();
		break;
	case R.id.cancel_auth:
		ShareSDK.getPlatform(mContext, SinaWeibo.NAME).removeAccount();
		ShareSDK.getPlatform(mContext, QZone.NAME).removeAccount();
		mSharedPreferences.edit().remove("login").commit();
		MobclickAgent.onEvent(mContext, "logout");
		Toast.makeText(mContext, R.string.logout_success,
				Toast.LENGTH_SHORT).show();
		break;
	case R.id.rate_for_us:
		Uri uri = Uri.parse("market://details?id="
				+ mContext.getPackageName());
		Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
		try {
			startActivity(goToMarket);
			MobclickAgent.onEvent(mContext, "rate");
		} catch (ActivityNotFoundException e) {
			Toast.makeText(mContext, R.string.can_not_open_market,
					Toast.LENGTH_SHORT).show();
		}
           break;
       case R.id.clear_cache:
           new Thread(){
               @Override
               public void run() {
                   super.run();
                   CacheUtils.deleteCache(mContext);
               }
           }.start();
           Toast.makeText(mContext,R.string.clear_ok,Toast.LENGTH_SHORT).show();
           break;
	default:
		break;
	}
}