All Products
Search
Document Center

Manage HTML5 pages

Last Updated: Feb 23, 2021

After opening an HTML5 offline package, you can perform the following management operations on an HTML5 page:

Start container parameter transfer in full-screen mode

  1. Bundle param = new Bundle();
  2. // The URL of the offline package to be opened, /www/index.html, in which the slash (/) must be added.
  3. // If no URL is transferred, the container opens the URL configured for the offline package by default. We recommend that you do not transfer a URL but an app ID so that the frontend can configure the page to be opened.
  4. param.putString(H5Param.LONG_URL,url);
  5. LauncherApplicationAgent.getInstance().
  6. getMicroApplicationContext().startApp(null, appId, param);
  7. // The h5Service.startPage method is used for a client connected to a container separately.
  8. public static final void openH5(String url) {
  9. if (TextUtils.isEmpty(url)) {
  10. return;
  11. }
  12. H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
  13. .findServiceByInterface(H5Service.class.getName());
  14. H5Bundle bundle = new H5Bundle();
  15. Bundle param = new Bundle();
  16. // The app ID of the offline package to be opened.
  17. param.putString(H5Param.APP_ID, appId);
  18. // The URL of the offline package to be opened, /www/index.html, in which the slash (/) must be added.
  19. // If no URL is transferred, the container opens the URL configured for the offline package by default. We recommend that you do not transfer a URL but an app ID so that the frontend can configure the page to be opened.
  20. param.putString(H5Param.LONG_URL,url);
  21. bundle.setParams(param);
  22. if (h5Service != null) {
  23. h5Service.startPage(AlipayApplication.getInstance().getMicroApplicationContext().findTopRunningApp(),
  24. bundle);
  25. }
  26. }

Embed the view of a single container into the page

Choose a method to embed the view of a single container into the HTML5 page based on the actual situation.

Note: The asynchronous method does not occupy the main thread and therefore does not compromise the performance.

Synchronous method

  1. public static final void openH5(String url) {
  2. if (TextUtils.isEmpty(url)) {
  3. return;
  4. }
  5. H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
  6. .findServiceByInterface(H5Service.class.getName());
  7. H5Bundle bundle = new H5Bundle();
  8. Bundle param = new Bundle();
  9. // The app ID of the offline package to be opened.
  10. param.putString(H5Param.APP_ID, appId);
  11. // The URL of the offline package to be opened, /www/index.html, in which the slash (/) must be added.
  12. If no URL is transferred, the container opens the URL configured for the offline package by default.
  13. param.putString(H5Param.LONG_URL,url);
  14. bundle.setParams(param);
  15. if (h5Service != null) {
  16. H5Page h5Page=h5Service.createPage(activity,bundle);
  17. View view=h5Page.getContentView(),
  18. // The view is finally added to the page.
  19. }
  20. }

Asynchronous method

  1. H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
  2. .findServiceByInterface(H5Service.class.getName());
  3. H5Bundle bundle = new H5Bundle();
  4. Bundle param = new Bundle();
  5. param.putString(H5Param.APP_ID, appId);
  6. param.putString(H5Param.LONG_URL, url);
  7. bundle.setParams(param);
  8. if (h5Service != null) {
  9. h5Service.createPageAsync(activity, bundle, h5PageReadyListener);
  10. }