public interface IWXAPI
WXAPIFactory
WXAPIFactory
创建实例限定符和类型 | 方法和说明 |
---|---|
void |
detach() |
int |
getWXAppSupportAPI()
get api level from installed wechat app
|
boolean |
handleIntent(android.content.Intent data,
IWXAPIEventHandler handler)
Call
handleIntent(Intent, IWXAPIEventHandler) in BroadcastReceiver. |
boolean |
isWXAppInstalled()
check wechat app installation status
|
boolean |
openWXApp()
launch wechat app
|
boolean |
registerApp(java.lang.String appId)
Register WeChat app.
|
boolean |
registerApp(java.lang.String appId,
long appSupportContentType)
Register WeChat app.
|
boolean |
sendReq(BaseReq req)
send request to wechat app
|
boolean |
sendResp(BaseResp resp)
send response to wechat app, make sure that the response have same transaction with request
|
void |
setLogImpl(ILog log) |
void |
unregisterApp()
Un-register WeChat app.
|
boolean registerApp(java.lang.String appId)
appId
- boolean registerApp(java.lang.String appId, long appSupportContentType)
appId
- appSupportContentType
- void unregisterApp()
boolean handleIntent(android.content.Intent data, IWXAPIEventHandler handler)
handleIntent(Intent, IWXAPIEventHandler)
in BroadcastReceiver. For example
class SampleEventProcessor extends BroadcastReceiver implements IWXAPIEventHandler {
// override broadcast receiver
public void onReceive(Context context, Intent data) {
final IWXAPI api = WXAPIFactory.createWXAPI(context, null);
if (api.handleIntent(data, this)) {
// intent handled as wechat request/response
return;
}
// process other intent as you like
}
// process request
public void onReq(BaseReq req) {
switch (req.getType()) {
case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
Toast.makeText(context, "get message from wx, processed here", Toast.LENGTH_LONG).show();
break;
case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
Toast.makeText(context, "show message from wx, processed here", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
// process response
public void onResp(BaseResp resp) {
switch (resp.getType()) {
case ConstantsAPI.COMMAND_SENDAUTH:
Toast.makeText(context, "get auth resp, processed here", Toast.LENGTH_LONG).show();
break;
case ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX:
// Process SendMessageToWX.Resp
returned by WeChat
Toast.makeText(context, "send messsage to wx resp, processed here", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}
and DON'T FORGET to add SampleEventProcessor BroadcastReceiver in AndroidManifest.xml
handleIntent(Intent, IWXAPIEventHandler)
,例如:
class SampleEventProcessor extends BroadcastReceiver implements IWXAPIEventHandler {
// override broadcast receiver
public void onReceive(Context context, Intent data) {
final IWXAPI api = WXAPIFactory.createWXAPI(context, null);
if (api.handleIntent(data, this)) {
// intent handled as wechat request/response
return;
}
// process other intent as you like
}
// process request
public void onReq(BaseReq req) {
switch (req.getType()) {
case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
Toast.makeText(context, "get message from wx, processed here", Toast.LENGTH_LONG).show();
break;
case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
Toast.makeText(context, "show message from wx, processed here", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
// process response
public void onResp(BaseResp resp) {
switch (resp.getType()) {
case ConstantsAPI.COMMAND_SENDAUTH:
Toast.makeText(context, "get auth resp, processed here", Toast.LENGTH_LONG).show();
break;
case ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX:
// 处理微信主程序返回的SendMessageToWX.Resp
break;
default:
break;
}
}
}
别忘了在AndroidManifest.xml中增加SampleEventProcessor这个BroadcastReceiver:
或者在代码中注册这个事件:
data
- handler
- boolean isWXAppInstalled()
int getWXAppSupportAPI()
boolean openWXApp()
boolean sendReq(BaseReq req)
req
- boolean sendResp(BaseResp resp)
resp
- void detach()
void setLogImpl(ILog log)