We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick AppAPIBasic FunctionsApp Context

App Context

API Declaration

No declaration is required.

Module Import

Add the following configuration to the script element on the page where the API will be called:

Collapse
Word wrap
Dark theme
Copy code
  1. import app from '@system.app'

Or

Collapse
Word wrap
Dark theme
Copy code
  1. var app = require("@system.app")

Application Scope

Expand

Item

Description

Applicable devices

Mobile phones, tablets, Vision products, and telematics devices

Applicable regions

Global

Definition

Expand

API

Description

app.getInfo()

Obtains current app information.

app.getPackageInfo(OBJECT)

Obtains information about a local app. In a quick app scenario, this API can obtain information about both the local native app and quick app. In a card scenario, this API can obtain only information about the native app.

app.createQuickAppQRCode (OBJECT)

Generates a QR code of the current quick app.

app. getUpdateManager()

Obtains an UpdateManager object.

UpdateManager.applyUpdate()

Forcibly restarts the quick app and uses its new version.

UpdateManager. onCheckForUpdate(function listener)

Listens to the quick app update check results.

UpdateManager.onUpdateReady(function listener)

Called when the new version is downloaded successfully.

UpdateManager.onUpdateFailed(function listener)

Called when the new version fails to be downloaded.

app.getInfo()

Description

Obtains current app information.

Returns

Expand

Parameter

Type

Description

name

string

Name of an app.

versionName

string

Name of an app version.

versionCode

number

Version code of an app.

logLevel

string

Log level.

source

object

App source.

icon (1045+)

string

Path of an app icon, which is configured in the manifest file. An example is /common/logo.png.

packageName (1045+)

string

App package name.

source parameters

Expand

Parameter

Type

Description

packageName

string

Package name of the source app. This is the level-1 source.

type

string

Source type. The options are as follows:

  • shortcut: shortcut icon
  • push: push message
  • url: web page
  • barcode: QR code scanning
  • nfc: access through NFC
  • bluetooth: access through Bluetooth
  • other: others

extra

object

Other source information, which varies with type.

When type is set to shortcut, the options of extra are as follows:

  • scene: shortcut creation scenario. The value can be dialog (created by the internal policy), api (created by calling an API), web (created when the traffic is switched from an HTML5 page), or other.
  • original: original source for shortcut creation.
NOTICE

The values of packageName and type will not be returned during app tests on Huawei Quick App Loader. They will be displayed after the app is officially released.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. console.log("App getInfo:"+ JSON.stringify(app.getInfo()));

The output is as follows:

Collapse
Word wrap
Dark theme
Copy code
  1. App getInfo:{
  2. "versionName":"1.0.0",
  3. "icon":"/Common/logo.png",
  4. "source":{
  5. "type":"unknown",
  6. "packageName":"unknown"
  7. },
  8. "versionCode":1,
  9. "logLevel":"debug",
  10. "name":"HelloWorld"
  11. }

app.getPackageInfo(OBJECT) (1050+)

Description

Obtains information about a local app. In a quick app scenario, this API can obtain information about both the local native app and quick app. In a card scenario, this API can obtain only information about the native app.

OBJECT

Expand

Parameter

Type

Mandatory

Description

packageName

string

Yes

Package name of the quick app or native app to be queried.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

Parameters returned by success

Expand

Parameter

Type

Description

versionName

string

Name of an app version.

versionCode

number

Version code of an app.

signatures

list<string>

App signature list. The signature belongs to the data publisher and is encrypted using SHA-256.

Result codes returned by fail

Expand

Result Code

Description

200

Common error.

202

Invalid parameter.

1000

The app is not installed.

app.createQuickAppQRCode (OBJECT) (1090+)

Description

Generates a QR code of the current quick app.

OBJECT

Expand

Parameter

Type

Mandatory

Description

path

string

No

Path to the page that supports carrying parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

Parameters returned by success

Expand

Parameter

Type

Description

uri

string

URI of the QR code file.

Result codes returned by fail

Expand

Result Code

Description

200

Common error.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. app.createQuickAppQRCode({
  2. path: '/interface/basic/router/detail',
  3. success: (data) => {
  4. this.packageInfo = JSON.stringify(data)
  5. this.srcUrl = data.uri;
  6. console.info('createQuickAppQRCode success', JSON.stringify(data))
  7. },
  8. fail: (errormsg, errorcode) => {
  9. this.packageInfo = 'get fail --- ' + errorcode + ':' + errormsg
  10. console.info('get fail --- ' + errorcode + ':' + errormsg)
  11. },
  12. complete: () => {
  13. console.info('get complete.')
  14. }
  15. })

Demo

Collapse
Word wrap
Dark theme
Copy code
  1. <template>
  2. <!-- Only one root node is allowed in template. -->
  3. <div class="container">
  4. <div class="item-container">
  5. <input type="button" class="btn" onclick="test_getappinfo" value="getAppInfo" />
  6. </div>
  7. <div class="item-container">
  8. <input type="button" class="btn" onclick="test_getpackageinfo" value="getPackageInfo" />
  9. </div>
  10. <div class="item-container" if="{{info}}">
  11. <text class="content">{{info}}</text>
  12. </div>
  13. </div>
  14. </template>
  15. <style>
  16. .container {
  17. flex-direction: column;
  18. justify-content: center;
  19. align-items: center;
  20. }
  21. .item-container {
  22. margin-top: 50px;
  23. margin-right: 30px;
  24. margin-left: 30px;
  25. flex-direction: column;
  26. }
  27. .btn {
  28. background-color: #0faeff;
  29. color: #ffffff;
  30. width:400px;
  31. height: 100px;
  32. font-size: 50px;
  33. border-radius:15px;
  34. }
  35. .content {
  36. border: 2px ;
  37. border-radius: 10px;
  38. text-align: center;
  39. }
  40. </style>
  41. <script>
  42. import app from '@system.app'
  43. module.exports = {
  44. data: {
  45. componentData: {},
  46. info:'',
  47. get_success:'',
  48. get_fail:''
  49. },
  50. onInit() {
  51. this.$page.setTitleBar({
  52. text: 'App Context',
  53. textColor: '#ffffff',
  54. backgroundColor: '#007DFF',
  55. backgroundOpacity: 0.5,
  56. menu: true
  57. });
  58. },
  59. test_getappinfo() {
  60. var that = this;
  61. // app.getInfo();
  62. var appinfo = JSON.stringify(app.getInfo());
  63. console.log("App getInfo:"+ appinfo);
  64. that.info = appinfo;
  65. that.get_success = appinfo;
  66. },
  67. test_getpackageinfo() {
  68. var that = this;
  69. app.getPackageInfo({
  70. packageName:'com.fast.rounter.app.huawei',
  71. success:function(data) {
  72. console.log("APP getPackageInfo is : "+data);
  73. that.info = data;
  74. that.get_success = data;
  75. },
  76. fail:function (data,code) {
  77. console.log(" get package info failed! " + code);
  78. console.log("get package info failed! "+data);
  79. that.info = data;
  80. that.get_fail = data;
  81. },
  82. complete:function(data) {
  83. console.log("complete!");
  84. that.info = data;
  85. }
  86. })
  87. }
  88. }
  89. </script>

The following figure shows the final effect.

Version Change History

Expand

Version

Date

Description

1090

2022-05-19

Added the app.createQuickAppQRCode API to generate the QR code of the current quick app.

1050

2019-09-20

  • Added icon and packageName to the app.getInfo API to obtain the app icon path and package name.
  • Added app.getPackageInfo to obtain information about local apps.

Links

Search in References
Enter a keyword.