獲取小程序棧堆和當前信息
更新時間:
您可以按照以下步驟,獲取小程序棧堆和當前信息。
創(chuàng)建
CustomApiBridgeExtension
類繼承SimpleBridgeExtension
類。代碼示例如下:public class CustomApiBridgeExtension extends SimpleBridgeExtension { private static final String TAG = "CustomApiBridgeExtension"; @ActionFilter public void tinyToNative(@BindingId String id, @BindingNode(App.class) App app, @BindingNode(Page.class) Page page, @BindingApiContext ApiContext apiContext, @BindingExecutor(ExecutorType.UI) Executor executor, @BindingRequest JSONObject params, @BindingParam("param1") String param1, @BindingParam("param2") String param2, @BindingCallback BridgeCallback callback) { RVLogger.d(TAG, "id: " + id + "\napp: " + app.toString() + "\npage: " + page.toString() + "\napiContext: " + apiContext.toString() + "\nexecutor: " + executor.toString()); RVLogger.d(TAG, JSONUtils.toString(params)); JSONObject result = BridgeResponse.SUCCESS.get(); // 將結(jié)果返回給小程序 Stack stack = MriverApp.getAppStack(); Enumeration enumerationLists = stack.elements(); JSONArray jsonArray = new JSONArray(); while (enumerationLists.hasMoreElements()) { JSONObject jsonObject = new JSONObject(); MRApp o = (MRApp) enumerationLists.nextElement(); jsonObject.put("AppId", o.getAppId()); jsonObject.put("AppVersion", o.getAppVersion()); jsonArray.add(jsonObject); } String tinyappStr = jsonArray.toJSONString(); // result.put("message", "客戶端接收到參數(shù):" + param1 + ", " + param2 + "\n返回 Demo 當前包名:" + apiContext.getActivity().getPackageName()); result.put("message", tinyappStr); callback.sendJSONResponse(result); } }
在啟動小程序之前進行注冊。
MriverEngine.registerBridge(CustomApiBridgeExtension.class);
啟動小程序。
Mriver.startApp(activity, "2021042620210426");
文檔內(nèi)容是否對您有幫助?