Android第三方应用分享图文到微信朋友圈 & 微信回调通知分享状态
2016-08-17 18:51
330 查看
原文 http://blog.csdn.net/wangyuexing_blog/article/details/21729117
主题 安卓开发
第一步:去微信开放平台(https://open.weixin.qq.com/)创建应用,并拿到AppId。
第二步:导入微信支持jar文件
。。。这里假设读者已经了解一般的第三方API开发,一些步骤就省略了。
第三步:发送图文消息到微信朋友圈(按钮触发事件里加入以下代码,请确保应用签名与在开放平台注册的应用签名一致,且AppId也应该对应)
如果一切顺利,就会看到了文章开头类似的图片。
这时点击取消或分享没有任何提示。
第四步:加提示回调页面。
(1)新建一个包
规则是你的程序包名加wxapi【例如:com.xxx.wxapi】
(2)在新建的包里面添加一个类,WXEntryActivity.java,名字必须一致,这是微信开放平台规定的。
(3)string.xml中添加一些字符item
(4)附上change_in.xml 和change_out.xml
最后:不管你在哪个地方调用第三步分享,微信都会有回调提示了。
===========THE===END=======================
主题 安卓开发
第一步:去微信开放平台(https://open.weixin.qq.com/)创建应用,并拿到AppId。
第二步:导入微信支持jar文件
。。。这里假设读者已经了解一般的第三方API开发,一些步骤就省略了。
第三步:发送图文消息到微信朋友圈(按钮触发事件里加入以下代码,请确保应用签名与在开放平台注册的应用签名一致,且AppId也应该对应)
IWXAPI api = WXAPIFactory.createWXAPI(context, APP_ID, false); api.registerApp(APP_ID); WXWebpageObject webpage = new WXWebpageObject(); webpage.webpageUrl = "http://www.xxxx.com/wap/showShare/; WXMediaMessage msg = new WXMediaMessage(webpage); msg.title = "我要约"; msg.description = "我要约分享"; try { Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.send_img); Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 150, 150, true); bmp.recycle(); msg.setThumbImage(thumbBmp); } catch (Exception e) { e.printStackTrace(); } SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = String.valueOf(System.currentTimeMillis()); req.message = msg; req.scene = SendMessageToWX.Req.WXSceneTimeline; api.sendReq(req);
如果一切顺利,就会看到了文章开头类似的图片。
这时点击取消或分享没有任何提示。
第四步:加提示回调页面。
(1)新建一个包
规则是你的程序包名加wxapi【例如:com.xxx.wxapi】
(2)在新建的包里面添加一个类,WXEntryActivity.java,名字必须一致,这是微信开放平台规定的。
package com.xxx.wxapi; import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import com.lbt.hairdesigner.R; import com.lbt.hairdesigner.utils.MySetting; import com.tencent.mm.sdk.openapi.BaseReq; import com.tencent.mm.sdk.openapi.BaseResp; import com.tencent.mm.sdk.openapi.IWXAPI; import com.tencent.mm.sdk.openapi.IWXAPIEventHandler; import com.tencent.mm.sdk.openapi.WXAPIFactory; public class WXEntryActivity extends Activity implements IWXAPIEventHandler { private IWXAPI api; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); api = WXAPIFactory.createWXAPI(this, APP_ID, false); api.registerApp(APP_ID); api.handleIntent(getIntent(), this); } @Override public void onReq(BaseReq req) { } @Override public void onResp(BaseResp resp) { int result = 0; switch (resp.errCode) { case BaseResp.ErrCode.ERR_OK: result = R.string.errcode_success; break; case BaseResp.ErrCode.ERR_USER_CANCEL: result = R.string.errcode_cancel; break; case BaseResp.ErrCode.ERR_AUTH_DENIED: result = R.string.errcode_deny; break; default: result = R.string.errcode_unknown; break; } Toast.makeText(this, result, Toast.LENGTH_LONG).show(); finish(); overridePendingTransition(R.anim.change_in, R.anim.change_out); } }
(3)string.xml中添加一些字符item
<string name="errcode_success">发送成功</string> <string name="errcode_cancel">发送取消</string> <string name="errcode_deny">发送被拒绝</string> <string name="errcode_unknown">发送返回</string>
(4)附上change_in.xml 和change_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator" > <scale android:duration="@android:integer/config_shortAnimTime" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%p" android:pivotY="50%p" android:toXScale="1.0" android:toYScale="1.0" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator" android:zAdjustment="top" > <scale android:duration="@android:integer/config_shortAnimTime" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%p" android:pivotY="50%p" android:toXScale="1.0" android:toYScale="1.0" /> <alpha android:duration="@android:integer/config_shortAnimTime" android:fromAlpha="1.0" android:toAlpha=".0" /> </set>
最后:不管你在哪个地方调用第三步分享,微信都会有回调提示了。
===========THE===END=======================
相关文章推荐
- zabbix微信报警
- Android集成微信刷卡支付遇到的坑坑洼洼
- 直接利用Android手机破解微信加密数据库EnMicroMsg.db
- 微信WeixinJSBridge API
- 微信内置浏览器私有接口WeixinJSBridge介绍
- 微信JSSDK接入Java版--步骤及问题处理和解决
- 【模拟微信时间轴】X分钟前,X小时前,X天前
- PHP微信开发框架LaneWeChat框架简介
- 【安全播报】微信突然变静音要谨慎,多人银行卡内余额被转走
- Android创建浮动的上下文菜单,实现微信通讯录列表长按弹出菜单项功能
- 浪漫的表白小程序
- 微信UnionID作用
- android 微信支付 invalid total fee
- android 微信支付 签名错误
- 微信支付获取prepay_id以及回调地址
- 微信支付工具类
- 微信公众号微信支付
- C# .net MVC 微信红包(服务号发送红包)
- 微信支付携手18家商户首创“早7晚5”优惠新玩法
- {html5} 微信刷新问题