1.首先要在微信开放平台(地址:https://open.weixin.qq.com/)注册账号,然后在“管理中心”创建你的移动应用,等待审核通过后,获取到该应用的APPID;
2.根据“资源中心”的接入指南,接入libammsdk.jar;
3.添加相关权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
代码:
private IWXAPI api;
api = WXAPIFactory.createWXAPI(getActivity(), Constants.WX_APP_ID, true); api.registerApp(Constants.WX_APP_ID);
WXWebpageObject webpage = new WXWebpageObject(); if (qrImgUrl == null){ Log.w("ss","qrImgUrl is null"); return; } webpage.webpageUrl = qrImgUrl; //分享链接 WXMediaMessage msg = new WXMediaMessage(webpage); msg.title = "分享的内容"; Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.erweima); //分享的图片 msg.thumbData = WechatShareUtil.bmpToByteArray(thumb, true); SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = String.valueOf(System.currentTimeMillis()); req.message = msg; req.scene = SendMessageToWX.Req.WXSceneSession; //WXSceneTimeline发送到朋友圈;WXSceneSession发送到聊天界面 api.sendReq(req);