com.tencent.mm.sdk.openapi
Interface IWXAPI


public interface IWXAPI

WeChat OpenAPI access interface

Entry of OpenAPI functions; creates instances via WXAPIFactory

微信OpenAPI访问入口

OpenAPI功能入口,使用时通过WXAPIFactory创建实例


Method Summary
 void detach()
           
 int getWXAppSupportAPI()
          get api level from installed wechat app
 boolean handleIntent(Intent data, IWXAPIEventHandler handler)
          
Call handleIntent(Intent, IWXAPIEventHandler) in BroadcastReceiver.
 boolean isWXAppInstalled()
          check wechat app installation status
 boolean isWXAppSupportAPI()
          check api level that supported by wechat app which has been installed
 boolean openWXApp()
          launch wechat app
 boolean registerApp(java.lang.String appId)
          
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 unregisterApp()
          
Un-register WeChat app.
 

Method Detail

registerApp

boolean registerApp(java.lang.String appId)
Register WeChat app. Registered apps will be shown in the app list of WeChat.
注册微信app,注册成功后该应用将显示在微信的app列表中

Parameters:
appId -
App ID of the third-party app
第三方应用的appId
Returns:
True if operation succeeded; and the app will be shown in WeChat. Otherwise not.
成功返回true,会显示在微信第三方列表中,否则不显示

unregisterApp

void unregisterApp()
Un-register WeChat app. The app will not be shown in WeChat app list if operation succeeded.
反注册微信app,成功后将不再显示在微信的app列表中


handleIntent

boolean handleIntent(Intent data,
                     IWXAPIEventHandler handler)
Call 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
在BroadcastReceiver中调用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:
  
             
                 
             
         
 
或者在代码中注册这个事件:

 
 
 

Parameters:
data -
handler -
Returns:
true if handled

isWXAppInstalled

boolean isWXAppInstalled()
check wechat app installation status

Returns:
true if installed

isWXAppSupportAPI

boolean isWXAppSupportAPI()
check api level that supported by wechat app which has been installed

Returns:
true if support

getWXAppSupportAPI

int getWXAppSupportAPI()
get api level from installed wechat app

Returns:
api level

openWXApp

boolean openWXApp()
launch wechat app

Returns:
true if launched

sendReq

boolean sendReq(BaseReq req)
send request to wechat app

Parameters:
req -
Returns:
true if sent

sendResp

boolean sendResp(BaseResp resp)
send response to wechat app, make sure that the response have same transaction with request

Parameters:
resp -
Returns:
true if sent

detach

void detach()