Android微信登入回撥類
阿新 • • 發佈:2019-02-07
/** * WXEntryActivity 微信回撥 包名與類名不能變 */ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { private IWXAPI api; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); api = WXAPIFactory.createWXAPI(this, Constants.WX_ID); api.handleIntent(getIntent(), this); } /** * 微信傳送請求到第三方應用時,會回撥到該方法 * * @param req 回撥 */ @Override public void onReq(BaseReq req) { LogUtil.e("----------------------------------------進入Req回撥----------------------------------------"); LogUtil.e("----------------------------------------進入Req回撥----------------------------------------"); LogUtil.e("----------------------------------------進入Req回撥----------------------------------------"); finish(); } /** * 第三方應用傳送到微信的請求處理後的響應結果,會回撥到該方法 * * @param resp 回撥 */ @Override public void onResp(BaseResp resp) { LogUtil.e("----------------------------------------進入Resp回撥----------------------------------------"); LogUtil.e("----------------------------------------進入Resp回撥----------------------------------------"); LogUtil.e("----------------------------------------進入Resp回撥----------------------------------------"); switch (resp.errCode) { case BaseResp.ErrCode.ERR_OK: LogUtil.i("----------------------success"); SharedPreferences getdata = getSharedPreferences("YA_USERINFO", Context.MODE_PRIVATE); SharedPreferences.Editor editor = getdata.edit(); editor.putString("code", ((SendAuth.Resp) resp).code); editor.apply(); finish(); break; case BaseResp.ErrCode.ERR_USER_CANCEL: LogUtil.i("----------------------cancel"); finish(); break; case BaseResp.ErrCode.ERR_AUTH_DENIED: LogUtil.i("----------------------refuse"); finish(); break; default: LogUtil.i("----------------------back"); finish(); break; } } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); api.handleIntent(intent, this); } }