First, apply for your AppID
http://open.weixin.qq.com/
Friendly tip: It is recommended to apply the MD5 value of the last step of the Eclipse Packaging software application AppID
Second, the official website download Libammsdk.jar Package
Http://open.weixin.qq.com/download/?lang=zh_CN
Iii. Copy the Libammsdk.jar to the Libs directory of the Project
Iv. writing code in activity that needs to be shared
Copy Code code as follows:
Private Iwxapi Wxapi;
Instantiation of
Wxapi = Wxapifactory.createwxapi (this, constants.wx_app_id);
Wxapi.registerapp (constants.wx_app_id);
/**
* Micro-credit sharing (only one example of sharing the Web page, please refer to the official website sample code)
* @param flag (0: Share to micro-trust friends, 1: Share to micro-trust friends Circle)
*/
private void Wechatshare (int flag) {
Wxwebpageobject webpage = new Wxwebpageobject ();
Webpage.webpageurl = "Fill in the link URL here";
Wxmediamessage msg = new Wxmediamessage (webpage);
Msg.title = "Fill in the title here";
Msg.description = "Fill in the content here";
Here, replace a picture resource in your own project.
Bitmap thumb = Bitmapfactory.decoderesource (Getresources (), R.drawable.share_logo);
Msg.setthumbimage (thumb);
Sendmessagetowx.req Req = new Sendmessagetowx.req ();
Req.transaction = string.valueof (System.currenttimemillis ());
Req.message = msg;
Req.scene = flag==0? SendMessageToWX.Req.WXSceneSession:SendMessageToWX.Req.WXSceneTimeline;
Wxapi.sendreq (req);
}
Add code where you need to share:
Wechatshare (0)//share to micro-trust friends
Wechatshare (1)//share to the micro-trust Friends Circle
Create a new WXAPI directory under your package name and add a wxentryactivity class to the Wxapi directory, which inherits from the activity and implements the Iwxapieventhandler interface
Copy Code code as follows:
/** micro-Credit Client callback activity sample * *
public class Wxentryactivity extends activity implements Iwxapieventhandler {
IWXAPI is the Openapi interface for third-party app and micro-communication
Private IWXAPI API;
@Override
protected void OnCreate (Bundle savedinstancestate) {
API = Wxapifactory.createwxapi (this, "replace the app_id that the first step applies", false);
Api.handleintent (Getintent (), this);
Super.oncreate (savedinstancestate);
}
@Override
public void Onreq (Basereq arg0) {}
@Override
public void Onresp (Baseresp resp) {
Logmanager.show (TAG, "Resp.errcode:" + Resp.errcode + ", Resp.errstr:"
+ RESP.ERRSTR, 1);
Switch (resp.errcode) {
Case BaseResp.ErrCode.ERR_OK:
Share success
Break
Case BaseResp.ErrCode.ERR_USER_CANCEL:
Share cancellation
Break
Case BaseResp.ErrCode.ERR_AUTH_DENIED:
Share rejection
Break
}
}
}
VI. Configuration manifest file Androidmanifest.xml
Copy Code code as follows:
<activity
Android:name= ". Wxapi. Wxentryactivity "
Android:exported= "true"
android:screenorientation= "Portrait"
Android:theme= "@android: Style/theme.translucent.notitlebar"/>
Seven, signed packaging software, and then you can test the