課程
/移動開發
/Android
/Android-心愿分享
WXEntryActivity.java文件時如何來的?從哪里下載?
2016-02-20
源自:Android-心愿分享 3-4
正在回答
微信給的示例,HelloWeixin@Android
package?net.sourceforge.simcpux.wxapi; import?com.tencent.mm.sdk.openapi.BaseReq; import?com.tencent.mm.sdk.openapi.BaseResp; import?com.tencent.mm.sdk.openapi.ConstantsAPI; import?com.tencent.mm.sdk.openapi.ShowMessageFromWX; import?com.tencent.mm.sdk.openapi.IWXAPI; import?com.tencent.mm.sdk.openapi.IWXAPIEventHandler; import?com.tencent.mm.sdk.openapi.WXAPIFactory; import?com.tencent.mm.sdk.openapi.WXAppExtendObject; import?com.tencent.mm.sdk.openapi.WXMediaMessage; import?net.sourceforge.simcpux.Constants; import?net.sourceforge.simcpux.GetFromWXActivity; import?net.sourceforge.simcpux.SendToWXActivity; import?net.sourceforge.simcpux.ShowFromWXActivity; import?net.sourceforge.simcpux.R; import?android.app.Activity; import?android.content.Intent; import?android.os.Bundle; import?android.view.View; import?android.widget.Button; import?android.widget.Toast; public?class?WXEntryActivity?extends?Activity?implements?IWXAPIEventHandler{ private?static?final?int?TIMELINE_SUPPORTED_VERSION?=?0x21020001; private?Button?gotoBtn,?regBtn,?launchBtn,?checkBtn; //?IWXAPI?是第三方app和微信通信的openapi接口 ????private?IWXAPI?api; ????@Override ????public?void?onCreate(Bundle?savedInstanceState)?{ ????????super.onCreate(savedInstanceState); ????????setContentView(R.layout.entry); ???????? ????????//?通過WXAPIFactory工廠,獲取IWXAPI的實例 ???? api?=?WXAPIFactory.createWXAPI(this,?Constants.APP_ID,?false); ???? regBtn?=?(Button)?findViewById(R.id.reg_btn); ???? regBtn.setOnClickListener(new?View.OnClickListener()?{ @Override public?void?onClick(View?v)?{ //?將該app注冊到微信 ????api.registerApp(Constants.APP_ID);???? } }); ???? ????????gotoBtn?=?(Button)?findViewById(R.id.goto_send_btn); ????????gotoBtn.setOnClickListener(new?View.OnClickListener()?{ @Override public?void?onClick(View?v)?{ ????????startActivity(new?Intent(WXEntryActivity.this,?SendToWXActivity.class)); ????????finish(); } }); ???????? ????????launchBtn?=?(Button)?findViewById(R.id.launch_wx_btn); ????????launchBtn.setOnClickListener(new?View.OnClickListener()?{ @Override public?void?onClick(View?v)?{ Toast.makeText(WXEntryActivity.this,?"launch?result?=?"?+?api.openWXApp(),?Toast.LENGTH_LONG).show(); } }); ???????? ????????checkBtn?=?(Button)?findViewById(R.id.check_timeline_supported_btn); ????????checkBtn.setOnClickListener(new?View.OnClickListener()?{ @Override public?void?onClick(View?v)?{ int?wxSdkVersion?=?api.getWXAppSupportAPI(); if?(wxSdkVersion?>=?TIMELINE_SUPPORTED_VERSION)?{ Toast.makeText(WXEntryActivity.this,?"wxSdkVersion?=?"?+?Integer.toHexString(wxSdkVersion)?+?"\ntimeline?supported",?Toast.LENGTH_LONG).show(); }?else?{ Toast.makeText(WXEntryActivity.this,?"wxSdkVersion?=?"?+?Integer.toHexString(wxSdkVersion)?+?"\ntimeline?not?supported",?Toast.LENGTH_LONG).show(); } } }); ???????? ????????api.handleIntent(getIntent(),?this); ????} @Override protected?void?onNewIntent(Intent?intent)?{ super.onNewIntent(intent); setIntent(intent); ????????api.handleIntent(intent,?this); } //?微信發送請求到第三方應用時,會回調到該方法 @Override public?void?onReq(BaseReq?req)?{ switch?(req.getType())?{ case?ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX: goToGetMsg(); break; case?ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX: goToShowMsg((ShowMessageFromWX.Req)?req); break; default: break; } } //?第三方應用發送到微信的請求處理后的響應結果,會回調到該方法 @Override public?void?onResp(BaseResp?resp)?{ int?result?=?0; switch?(resp.errCode)?{ case?BaseResp.ErrCode.ERR_OK: result?=?R.string.errcode_success; break; case?BaseResp.ErrCode.ERR_USER_CANCEL: result?=?R.string.errcode_cancel; break; case?BaseResp.ErrCode.ERR_AUTH_DENIED: result?=?R.string.errcode_deny; break; default: result?=?R.string.errcode_unknown; break; } Toast.makeText(this,?result,?Toast.LENGTH_LONG).show(); } private?void?goToGetMsg()?{ Intent?intent?=?new?Intent(this,?GetFromWXActivity.class); intent.putExtras(getIntent()); startActivity(intent); finish(); } private?void?goToShowMsg(ShowMessageFromWX.Req?showReq)?{ WXMediaMessage?wxMsg?=?showReq.message; WXAppExtendObject?obj?=?(WXAppExtendObject)?wxMsg.mediaObject; StringBuffer?msg?=?new?StringBuffer();?//?組織一個待顯示的消息內容 msg.append("description:?"); msg.append(wxMsg.description); msg.append("\n"); msg.append("extInfo:?"); msg.append(obj.extInfo); msg.append("\n"); msg.append("filePath:?"); msg.append(obj.filePath); Intent?intent?=?new?Intent(this,?ShowFromWXActivity.class); intent.putExtra(Constants.ShowMsgActivity.STitle,?wxMsg.title); intent.putExtra(Constants.ShowMsgActivity.SMessage,?msg.toString()); intent.putExtra(Constants.ShowMsgActivity.BAThumbData,?wxMsg.thumbData); startActivity(intent); finish(); } }
予給 提問者
qq_又小雪_0
舉報
用Android開發一款心愿分享APP,個性心意,分享祝福
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-02-20
微信給的示例,HelloWeixin@Android