After you integrate the WindVane or uni-app miniapp container into a native app, you can search for miniapps, obtain a list of miniapps, or start a miniapp.
Obtain a list of miniapps
The miniapp container SDK provides an interface for obtaining a list of miniapps. If you only want to obtain the miniapp list, you can directly use this interface. The callback methods of the interface are called from the UI thread. If you want to perform other operations, we recommend that you use the relevant APIs provided by SuperApp.
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService != null) {
miniAppService.getMiniAppList(this, new OnQueryMiniAppsListener() {
@Override
public void onSuccess(List<MiniAppInfo> miniAppInfos, String anchor) {
// Return a list of miniapps. By default, a maximum of 10 miniapps can be obtained. The anchor parameter is used to obtain more miniapps.
}
@Override
public void onFailed(int errorCode) {
}
});
}Search for miniapps
The miniapp container SDK provides an interface for searching for miniapps. If you only want to search for miniapps, you can directly use this interface. The callback methods of the interface are called from the UI thread. If you have other search requirements, we recommend that you use the relevant APIs provided by SuperApp.
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService != null) {
// The keyword parameter specifies the search keyword.
miniAppService.queryMiniApps(this, keyword, new OnQueryMiniAppsListener() {
@Override
public void onSuccess(List<MiniAppInfo> miniAppInfos, String anchor) {
// Return the search results. By default, a maximum of 10 miniapps can be obtained. The anchor parameter is used to obtain more miniapps.
}
@Override
public void onFailed(int errorCode) {
}
});
}Start a miniapp
You can start a miniapp by using its ID. WindVane miniapps and uni-app miniapps can be started in the same manner. Loading a miniapp requires a specific period of time. We recommend that you add code to associated callback methods to initialize or update UI elements. The callback methods are called from the UI thread.
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService != null) {
miniAppService.openMiniApp(mItemView.getContext(), "151160916074102445****", null, new OnOpenMiniAppListener() {
//151160916074102445**** indicates the ID of the miniapp, which is obtained from Application Open Platform.
@Override
public void onOpenMiniApp() {
// You can implement this method to show a loading indicator on the UI when the miniapp starts to load.
}
@Override
public void onOpenSuccess(String appId) {
// You can implement this method to hide the loading indicator on the UI when the miniapp is started.
}
@Override
public void onOpenFailed(String appId, int errorCode) {
// You can implement this method to hide the loading indicator on the UI when the miniapp fails to be started.
}
});
}Open a specific page within a miniapp
When you start a miniapp, you can configure the path parameter to open a specific page within the miniapp and use extraData to pass arguments to the page.
For a uni-app miniapp, the path parameter specifies the absolute URL of the miniapp page and extraData is a JSON object used to pass startup arguments to the miniapp. After the miniapp is started, you can retrieve values from extraData by using the plus.runtime.arguments method.
To open a page within a WindVane miniapp, you can access a URL in the following format: https://{appId}.app.mini.windvane.suite.emas.alibaba.com/index.html#/{path}?key=value&key2=123. When you develop miniapps, you must use hash routing to handle the logic of page navigation.
MiniAppOpenConfiguration config = new MiniAppOpenConfiguration();
config.path = "/test";
JSONObject arguments = new JSONObject();
arguments.put("MSG","Hello miniApp");
config.extraData = arguments;
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService != null) {
miniAppService.openMiniApp(v.getContext(), "151160916074102445****", config, new OnOpenMiniAppListener() {
//151160916074102445**** indicates the ID of the miniapp, which is obtained from Application Open Platform.
@Override
public void onOpenMiniApp() {
// You can implement this method to show a loading indicator on the UI when the miniapp starts to load.
}
@Override
public void onOpenSuccess(String appId) {
// You can implement this method to hide the loading indicator on the UI when the miniapp is started.
}
@Override
public void onOpenFailed(String appId, int errorCode) {
// You can implement this method to hide the loading indicator on the UI when the miniapp fails to be started.
}
});
}Preview a MiniApp
By using the "miniapp ID" and "publishId", you can preview the miniapp. Generally, preview parameters are obtained by scanning the QR Code on an Open Platform, and then the preview is started referring to the following example code.
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService != null) {
miniAppService.previewMiniApp(context, "151160916074102445****", "P79127424345890****", null, new OnOpenMiniAppListener() {
// 151160916074102445****: MiniApp ID
// P79127424345890****: publishid
@Override
public void onOpenMiniApp() {
// Start previewing the miniapp,
// loading prompt can be displayed on the UI
}
@Override
public void onOpenSuccess(String appId) {
// Preview mini program successful,
// loading prompt can be hidden on UI
}
@Override
public void onOpenFailed(String appId, int errorCode) {
// Preview mini program failed,
// loading prompt can be hidden on UI
}
});
}Fetch Mini-App List Within a Category
The mini-app container SDK offers an interface for fetching a list of mini-apps within a specific category.
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService != null) {
miniAppService.queryMiniAppCategories(context, new OnQueryMiniAppCategoryListener() {
@Override
public void onSuccess(List<MiniAppCategory> miniAppCategories) {
// Displays the list of mini-apps within a single category.
}
@Override
public void onFailed(int errorCode, String errorMsg) {
}
});
}Preload Mini-App Resources
The mini-app container SDK provides an interface for preloading mini-app resources.
IMiniAppService miniAppService = ServiceManager.getInstance().getService(IMiniAppService.class.getName());
if (miniAppService!=null){
miniAppService.preloadMiniApp(context, "151160916074102445****", new OnPreloadMiniAppListener() {
// "151160916074102445****" signifies the mini-app ID, obtained from the application open platform.
@Override
public void onPreloadSuccess(String appId) {
//Triggered upon successful preloading of resources
}
@Override
public void onPreloadFailed(String appId, int errorCode) {
//Invoked when preloading resources fails
}
});
}