微信分享,通过ShareSDK完成

1:先去ShareSDK平台注册账号,关键是获取AppKey,这玩意在你集成ShareSDK分享组件的时候会用得上

2:把ShareSDK分享组件集成到app中,详情参考http://wiki.mob.com/android-sharesdk%e5%ae%8c%e6%95%b4%e7%9a%84%e9%9b%86%e6%88%90%e6%96%87%e6%a1%a3/

3:上微信开发者平台搞到AppId和AppSecret,没有账号的请注册一个,如无意外都要交300大元的申请费用,详细教程http://bbs.mob.com/thread-95-1-4.html

微信开发者官网http://open.weixin.qq.com

4:ShareSDK做了一个九宫格的傻瓜式组件,我一般是不用了,为了迎合产品经理与设计师的审美需求,我更多的是用自定义api

这里我做了一下封装,方便使用,ps:调用ShareSDK的api需要初始化


public class ShareUtils {
	private Context mContext;

	private ShareUtils() {
	}

	private static class ShareUtilsFactory {
		private static ShareUtils instance = new ShareUtils();
	}

	/* 获取实例 */
	public static ShareUtils getInstance() {
		return ShareUtilsFactory.instance;
	}

	public void init(Context ctx) {
		mContext = ctx;
		ShareSDK.initSDK(mContext);
	}
  
    
/**
	 * 分享到微信好友
	 * @param bundle
	 */	

public void shareWechat(Bundle bundle) {
		ShareParams sp = new ShareParams();
		sp.setShareType(Platform.SHARE_WEBPAGE);// 设置成分享网页
		String title, summary, thumb, url;
		title=bundle.getString("title");
		summary=bundle.getString("summary");
		thumb=bundle.getString("thumb");
		url=bundle.getString("url");
		sp.setTitle(title);
		sp.setText(summary);
		sp.setShareType(Platform.SHARE_WEBPAGE);
		sp.setImageUrl(thumb);
		sp.setUrl(url);
		Platform wechat = ShareSDK.getPlatform(Wechat.NAME);
		wechat.setPlatformActionListener(new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int arg1, Throwable arg2) {
		
			}

			@Override
			public void onComplete(Platform arg0, int arg1,
					HashMap<String, Object> arg2) {

			}

			@Override
			public void onCancel(Platform arg0, int arg1) {

			}
		});
		wechat.share(sp);
	}

/**
	 * 分享到微信朋友圈
	 * @param bundle
	 */

	public void shareWechatMoments(Bundle bundle) {
		ShareParams sp = new ShareParams();
		String title, summary, thumb, url;
		title=bundle.getString("title");
		summary=bundle.getString("summary");
		thumb=bundle.getString("thumb");
		url=bundle.getString("url");

		sp.setTitle(title);
		sp.setText(summary);
		sp.setShareType(Platform.SHARE_WEBPAGE);
		sp.setImageUrl(thumb);
		sp.setUrl(url);

		Platform wechatmoments = ShareSDK.getPlatform(WechatMoments.NAME);
		wechatmoments.setPlatformActionListener(new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int arg1, Throwable arg2) {

		
			}

			@Override
			public void onComplete(Platform arg0, int arg1,
					HashMap<String, Object> arg2) {

			}

			@Override
			public void onCancel(Platform arg0, int arg1) {

	
			}
		});
		wechatmoments.share(sp);
	}

}

调用:

ShareUtils.getInstance().init(context);// 初始化分享工具

shareUtils = ShareUtils.getInstance();


Bundle bundle = new Bundle();
bundle.putString("title", "分享测试标题");
bundle.putString("summary", "测试摘要");
bundle.putString("thumb", "缩略图链接");
bundle.putString("url", "网页链接,请自行替换");

shareUtils.shareWechat(bundle);//分享到微信好友

shareUtils.shareWechatMoments(bundle);//分享到微信朋友圈

更多api说明

http://wiki.mob.com/%e5%88%86%e4%ba%ab%e5%88%b0%e6%8c%87%e5%ae%9a%e5%b9%b3%e5%8f%b0/

 

5:因为测试所用的应用签名是系统默认的,和正式上线时的签名不一样(自己生成的xxx.keystores),如果不同时修改微信官网登记的签名,就会导致正式发布的包分享失败,很简单,在导出正式包的时候可以查看所使用的应用签名,或者用微信提供的安卓签名查看工具,知道正式的签名,在微信官网上修改就可以了,无需等待官方审核。

 

转载于:https://my.oschina.net/carbenson/blog/752072

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值