WXEntryActivity

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/feng88724/article/details/52694565

写法一:

import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {

    private IWXAPI api;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("WXEntryActivity", "onCreate");
        api = WXAPIFactory.createWXAPI(this, APP_ID_WECHAT, false);
        api.registerApp(APP_ID_WECHAT);  
        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.e("WXEntryActivity", "onNewIntent");
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq arg0) {
        // TODO Auto-generated method stub
        Log.e("WXEntryActivity", "onReq");
    }

    @Override
    public void onResp(BaseResp resp) {
        Log.e("WXEntryActivity", "onResp");
        // TODO Auto-generated method stub
        if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
            // 用户同意
            Log.e("WXEntryActivity", "onResp" + resp.errCode);
            Log.e("WXEntryActivity", "onResp" + resp.errStr);
            Log.e("WXEntryActivity", "onResp" + resp.openId);
        }
    }
}

写法二:

import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class WXEntryActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("WXEntryActivity", "onCreate");
        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.e("WXEntryActivity", "onNewIntent");
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        SendAuth.Resp resp = new SendAuth.Resp(intent.getExtras());
        if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
            Log.e("WXEntryActivity", "handleIntent" + resp.errCode);
            Log.e("WXEntryActivity", "handleIntent" + resp.errStr);
            Log.e("WXEntryActivity", "handleIntent" + resp.openId);
            Log.e("WXEntryActivity", "handleIntent" + resp.code);
        }
    }
}
阅读更多

没有更多推荐了,返回首页