All Products
Document Center

Manage offline packages

Last Updated: Mar 24, 2021

Offline package management operations include: Preload an HTML5 app, Use the global resource package, Update an HTML5 app, Download an HTML5 app, Install an HTML5 app, Obtain app information, Verify the security signature, and Delete local app information .


Preload an HTML5 app

Generally, the offline package may have not been downloaded when an HTML5 app is opened for the first time. In this case, you need to open the app by using the fallback URL.

Preloading an HTML5 app involves preinstalling an available HTML5 app in the installation package released by the client. When opening a preinstalled app for the first time, the user can directly use the offline package resources, which improves user experience.

Note: We recommend that you preinstall only core HTML5 apps and do not preinstall apps with a low usage rate.

To preload an HTML5 App, you need to complete the following steps:

  1. Download the HTML5 app configuration file .json and required offline packages from the HTML5 app release backend.
  2. Add the .json file and offline packages to the asset directory of the project.
  3. When the app is started, call the preload code to install the app. The code sample is as follows:
    1. MPNebula.loadOfflineNebula("h5_json.json", new MPNebulaOfflineInfo("90000000_1.0.0.6.amr", "90000000", ""));
    • This method is a block-type call method. Do not call the offline package method embedded on the main thread.
    • This method can be called only once. If it is called multiple times, only the first call is valid. Therefore, you need to input the information about all required offline packages at a time.
    • If multiple amr packages are embedded, ensure that the file already exists. If it does not exist, other embedded offline packages will fail.

Use the global resource package

The Nebula global resource package addresses redundancy caused by multiple HTML5 apps using the same resource. For example, the React app uses the ReactJS framework code. You can include public resources into the global resource package to downsize the HTML5 app.

Generally, a global resource package needs to be preset for the project, and subsequent updates can still be delivered through the HTML5 app backend.

The following code sample specifies the resource package with the app ID (appId) 66666692 as the global resource package and presets the assets/nebulaPreset/66666692 offline package.

  • getCommonResourceAppList: notifies the HTML5 container that an offline package with the specified ID will be used as the global resource package. If this ID is not configured, this offline package does not take effect even if it is embedded.
  • getH5PresetPkg: specifies the path and version of the embedded global resource package. The HTML5 container loads the resource package from the specified asset resource directory. However, if a later version is detected on the server, this embedded package of an earlier version will not be loaded. In addition, you can use the aforementioned loadOffLineNebula method to preset a global resource package. In this case, you do not need to specify the path and version of the embedded offline package in this method.
    Note: This method applies only to an HTML5 global resource package.
  • getTinyCommonApp: returns the framework resource package ID of a mini app. If your global resource package is used only by the HTML5 container, do not write the ID of this public resource package in this method.

Reference code sample:

  1. public class H5AppCenterPresetProviderImpl implements H5AppCenterPresetProvider {
  2. private static final String TAG = "H5AppCenterPresetProviderImpl";
  3. // Set a resource package dedicated to a mini app.
  4. private static final String TINY_COMMON_APP = "66666692";
  5. // The asset directory of the preset package.
  6. private final static String NEBULA_APPS_PRE_INSTALL = "nebulaPreset" + File.separator;
  7. // The preset package set.
  8. private static final Map<String, H5PresetInfo> NEBULA_LOCAL_PACKAGE_APP_IDS = new HashMap();
  9. static {
  10. H5PresetInfo h5PresetInfo2 = new H5PresetInfo();
  11. // The file name of the embedded directory.
  12. h5PresetInfo2.appId = TINY_COMMON_APP;
  13. h5PresetInfo2.version = "";
  14. h5PresetInfo2.downloadUrl = "";
  16. }
  17. @Override
  18. public Set<String> getCommonResourceAppList() {
  19. Set<String> appIdList = new HashSet<String>();
  20. appIdList.add(getTinyCommonApp());
  21. return appIdList;
  22. }
  23. @Override
  24. public H5PresetPkg getH5PresetPkg() {
  25. H5PresetPkg h5PresetPkg = new H5PresetPkg();
  26. h5PresetPkg.setPreSetInfo(NEBULA_LOCAL_PACKAGE_APP_IDS);
  27. h5PresetPkg.setPresetPath(NEBULA_APPS_PRE_INSTALL);
  28. return h5PresetPkg;
  29. }
  30. /**
  31. *Set a downgradable resource package ID.
  32. */
  33. @Override
  34. public Set<String> getEnableDegradeApp() {
  35. return null;
  36. }
  37. @Override
  38. public String getTinyCommonApp() {
  39. return TINY_COMMON_APP;
  40. }
  41. @Override
  42. public InputStream getPresetAppInfo() {
  43. return null;
  44. }
  45. @Override
  46. public InputStream getPresetAppInfoObject() {
  47. return null;
  48. }
  49. }

Call the following code when the App starts:

  1. H5Utils.getH5ProviderManager().setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());

Update an HTML5 app

By default, Nebula checks for a later version each time an HTML5 app is opened. Considering the pressure on the server, the check duration is restricted and is 30 minutes by default. To immediately check for the latest available version, call the following code to request for an update. Generally, the code can be called after the app starts or after the user logs on.

  1. MPNebula.updateAllApp(new MpaasNebulaUpdateCallback(){
  2. @Override
  3. public void onResult(final boolean success, final boolean isLimit) {
  4. super.onResult(success, isLimit);
  5. runOnUiThread(new Runnable() {
  6. @Override
  7. public void run() {
  8. AUToast.makeToast(NebulaAppActivity.this,
  9. success ? R.string.update_success : R.string.update_failure, 2000).show();
  10. }
  11. });
  12. }
  13. });

Download an HTML5 app

The MPNebula API allows you to manually download an HTML5 app.

  1. /**
  2. *Download an offline package.
  3. *
  4. * @param appId: offline package ID
  5. * @param mpaasNebulaDownloadCallback: download callback
  6. */
  7. public static void downloadApp(final String appId, final MpaasNebulaDownloadCallback mpaasNebulaDownloadCallback)

Install an HTML5 app

The MPNebula API allows you to manually install an HTML5 app.

  1. /**
  2. *Install an offline package.
  3. *
  4. * @param appId: offline package ID
  5. * @param mpaasNebulaInstallCallback: installation callback
  6. */
  7. public static void installApp(final String appId, final MpaasNebulaInstallCallback mpaasNebulaInstallCallback)

Obtain app information

Call the H5AppProvider method to obtain related information about HTML5 apps.

  1. H5AppProvider provider = H5Utils.getProvider(H5AppProvider.class.getName());
  2. AppInfo appInfo = provider.getAppInfo("1000000"); // Obtain app configuration.
  3. boolean isInstalled = provider.isInstalled("100000", ""); // Whether an app version is installed.
  4. boolean isAvailable = provider.isAvailable("100000", "");// Whether the offline package of an app version is downloaded successfully.

Verify the security signature

Nebula has an offline package signature verification mechanism to prevent malicious programs from tampering with offline packages downloaded to the device. Call MPNebula interface to use signature verification. In 10.1.60 and above, additional container configuration is required. See HTML5 container configuration for details.

  • Call this API before opening the offline package for the first time. Otherwise, public key initialization fails.About public and private keys, see Configure offline packages.
  • Signature verification is forcibly performed on a mobile phone judged as root, regardless of whether signature verification is enabled on the client.
  1. ```java
  2. /**
  3. * @param publicKey: public key for signature verification
  4. */
  5. public static void enableAppVerification(final String publicKey)
  6. ```

Delete local app information

Nebula provides the interface for deleting local app information. After local app information is deleted, the client side will send request to the service side to download and update local app when the app is opened again.

  1. public class MPNebula {
  2. // appId is the ID of the offline package or the mini program
  3. public static boolean deleteAppInfo(String appId);
  4. }
Note: The lowest baseline versions supported by this API are and respectively.