Initialize an API
Method 1
You can use the mPaaS infrastructure component initialization method to set additional
mriverparameters.// Initialization public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // mPaaS initialization callback settings QuinoxlessFramework.setup(this, new IInitCallback() { @Override public void onPostInit() { // Initialize the logic of other mPaaS components } }); } @Override public void onCreate() { super.onCreate(); // Initialize mPaaS. QuinoxlessFramework.init(); } }Add the
metaconfiguration to theAndroidManifest.xml:<meta-data android:name="mpaas.init.param" android:value="com.mpaas.demo.MriverInitImpl" />Add
com.mpaas.demo.MriverInitImplclasses to implementMPInitParamManifest.public class MriverInitImpl implements com.mpaas.MPInitParamManifest { @Override public MPInitParam initParam() { MriverInitParam mriverInitParam = createInitParams(); return MPInitParam.obtain().addComponentInitParam(mriverInitParam); } }
Method 2
Initialize the API by using the MPInit.init(Application application, MPInitParam param) method of MPInit.
MP.init(this, createInitParams());
MPInitParam createInitParams() {
final MriverInitParam mriverInitParam = MriverInitParam.getDefault();
mriverInitParam.setMriverInitCallback(new MriverInitParam.MriverInitCallback() {
@Override
public void onInit() {
MPLogger.setUserId("MPTestCase");
if (com.alibaba.ariver.kernel.common.utils.ProcessUtils.isMainProcess()) {
// Configure the mini program, such as JSAPI and titlebar.
Log.i("MriverApp", "init1");
Mriver.setConfig("mr_use_inner_net", "YES");
Mriver.setConfig("mr_request_support_gzip", "true");
Mriver.setConfig("mr_showShareMenuItem", "YES");
Mriver.setConfig("mriver_openlocation_hidden_default", "0");
Mriver.setConfig("mriver_support_chooseFile", "YES");
Mriver.setConfig("ta_worker_init_low_version_compat", (Build.VERSION.SDK_INT == 22 || Build.VERSION.SDK_INT == 21) ? "YES" : "NO");
MriverEngine.registerBridge(ShareApiBridgeExtension.class);
MriverEngine.registerBridge(SnapshotScreenApiBridgeExtension.class);
Mriver.enableAPM();
List<String> miniAppPoint = new ArrayList<>();
miniAppPoint.add(PageResumePoint.class.getName());
miniAppPoint.add(PageEnterPoint.class.getName());
Mriver.registerPoint(PageLifeCycleExtension.class.getName(), miniAppPoint);
RVProxy.set(PrepareNotifyProxy.class, new PrepareNotifyProxy() {
@Override
public void notify(String s, PrepareStatus prepareStatus) {
}
@Override
public void apmEvent(final String s, final String s1, final String s2, final String s3, final String s4) {
mUIHandler.post(new Runnable() {
@Override
public void run() {
if (APMActivity.logs == null) {
APMActivity.logs = new StringBuilder();
}
APMActivity.logs.append(s).append(" ").append(s1).append(" ").append(s2).append(" ").append(s3).append(" ").append(s4).append("\n");
if (TextUtils.equals(s, "MiniAppStart")
|| TextUtils.equals(s, "MiniPage_Load_T2")) {
Toast.makeText(MRiverApp.sApp, "startTime: " + s4, Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
Log.i(TAG, "registerPlugin");
MPNebula.registerH5Plugin(
PagePlugin.class.getName(),
null,
"page",
new String[]{"myapi2", H5Plugin.CommonEvents.H5_SESSION_EXIT, H5Plugin.CommonEvents.H5_PAGE_CLOSED, H5Plugin.CommonEvents.H5_PAGE_FINISHED, H5Plugin.CommonEvents.H5_PAGE_SHOULD_LOAD_URL}
);
MriverEngine.enableDebugConsole();
Mriver.setConfig("mriver_show_debug_menu_all", "YES");
Log.i("TTAATT", "hasInited");
}
@Override
public void onError(Exception e) {
Log.i("MriverApp", "init2");
}
});
mriverInitParam.setUCInitCallback(new MriverInitParam.UCInitCallback() {
@Override
public void onInit() {
sHasUCInit = true;
Log.i("TTAATT", "hasInitedUC");
}
@Override
public void onError(Exception e) {
}
});
return MPInitParam.obtain().setCallback(this).addComponentInitParam(mriverInitParam);
}Startup and Configuration
Mriver Framework Global API
Method | Description | Must be called |
void setUserId(String userId) | Set the | Yes |
void startApp(String appId) | Start the mini program as | Yes |
void startApp(Activity activity, String appId, Bundle startParams) | Start the mini program according to the | |
void setConfig(String key, String value) | The configuration of the mini program container. For more information about the configuration parameters, see Switch configuration. | No |
void forcePermissionCheck() | Forced permission verification. After you enable this feature, a pop-up window appears when mini programs call permission-related APIs. | No |
void setProxy(Class<T> proxyClazz, T proxyImpl) | Configure the container proxy. For more information about the custom logic, see Function configuration. | No |
void registerPoint(String className, List<String> pointsClassName) | Listen to various facets of the container. For more information, see Function configuration. | No |
MriverResource Resource Management
Method | Description | Must be called |
void updateApp(Map<String, String> appList, UpdateAppCallback callback) | Update a specific mini program. The | As needed, you can update in advance to optimize the first load performance. |
void updateApp(String appId, String targetVersion, UpdateAppCallback callback) | Updates to the specified version. | As needed |
void downloadAppPackage(String appId) | Download the mini program. | As needed |
AppModel getAppModel(String appId) | You can call this operation to obtain information about an existing local mini program. | As needed |
void enableVerify(String type, String publicRsa) | Enable signature verification.
| Must be called, turn on or off depending on the choice |
void disableVerify() | Disable the package experience tab. | |
void deleteApp(String appId) | Deletes a local mini program. | As needed |
void enableAPM() | Enable APM reporting. | As needed |
Map<String, List<AppModel>> getAllApp() | Obtains all local mini programs. | As needed |
MriverEngine API
Method | Description | Must be called |
void registerBridge(Class<? extends BridgeExtension> bridgeClass) | Custom JSAPI. | As needed |
void sendToRender(Page page, String event, @Nullable JSONObject data, @Nullable SendToRenderCallback callback) | Native sends a message to the mini program. | As needed |
void setUserAgent(final String customUa) | Set | As needed |
void enableDebugConsole | Open the debug panel. | As needed |
MriverDebug API
Method | Description | Must be called |
void setWssHost(String wssHost) | Set the WSS address for real machine debugging. | You must call the |
void debugAppByScan(Activity activity) | Preview /real machine debugging scan code. | You must call the |
void debugAppByScan(final Activity activity, Bundle bundle) | Preview /real machine debugging scan code, and add startup parameters. |