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 AppAPISystem CapabilitiesApp Management

App Management

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

Collapse
Word wrap
Dark theme
Copy code
  1. {"name": "system.package"}

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 pkg from '@system.package'

Or

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

Application Scope

Expand

Item

Description

Applicable devices

Mobile phones, tablets, Vision products, and telematics devices

Applicable regions

Global

Definition

Expand

API

Description

pkg.hasInstalled(OBJECT)

Checks whether a native or quick app has been installed. A quick app is considered installed only when a home screen icon has been created for it.

pkg.install(OBJECT)

Goes to the app details page on AppGallery for the user to install the native app. This API does not check whether the installation is successful.

pkg.getInfo(OBJECT)

Obtains the version name and version code of an app.

pkg.getSignatureDigests(OBJECT)

Obtains app signature digests.

pkg.hasInstalled(OBJECT)

Description

Checks whether a native or quick app has been installed. A quick app is considered installed only when a home screen icon has been created for it.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

package

string

Yes

App package name.

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

result

boolean

Indicates whether the app exists.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pkg.hasInstalled({
  2. package: 'com.hap.app',
  3. success: function(data) {
  4. console.log("handling success: " + data.result);
  5. },
  6. fail: function(data, code) {
  7. console.log("handling fail, code=" + code);
  8. }
  9. })

pkg.install(OBJECT)

Description

Goes to the app details page on AppGallery for the user to install the native app. This API does not check whether the installation is successful.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

package

string

Yes

App package name.

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

result

boolean

Indicates whether the app details page on AppGallery is displayed.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pkg.install({
  2. package: 'com.hap.app',
  3. success: function(data) {
  4. console.log("handling success: " + data.result);
  5. },
  6. fail: function(data, code) {
  7. console.log("handling fail, code=" + code);
  8. }
  9. })

pkg.getInfo(OBJECT) (1070+)

Description

Obtains the version numbers and version names of the native app and the quick app.

NOTE

For a card, only the information about the installed native app can be obtained.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

package

string

Yes

App package name.

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

versionCode

number

Version code mapping the queried package name.

versionName

string

Version name mapping the queried package name.

Result codes returned by fail

Expand

Result Code

Description

202

Invalid parameter.

1000

No apps found.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pkg.getInfo({
  2. package: 'com.sina.news',
  3. success: function (data) {
  4. console.log(`handling success: ${data.versionCode}, ${data.versionName}`)
  5. },
  6. fail: function (data, code) {
  7. console.log(`handling fail, code = ${code}`)
  8. }
  9. })

pkg.getSignatureDigests(OBJECT) (1070+)

Description

Obtains the signature digest of the native app and quick app.

NOTE

For a card, only the information about the installed native app can be obtained.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

package

string

Yes

App package name.

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

signatureDigests

array

List of signatures encrypted using the SHA-256 algorithm.

Result codes returned by fail

Expand

Result Code

Description

202

Invalid parameter.

1000

No apps found.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pkg.getSignatureDigests({
  2. package: 'com.sina.news',
  3. success: function (data) {
  4. data.signatureDigests.map(function (item) {
  5. console.log(`handling success: signatureDigests = ${item}`)
  6. })
  7. },
  8. fail: function (data, code) {
  9. console.log(`handling fail, code = ${code}`)
  10. }
  11. })

Demo

Collapse
Word wrap
Dark theme
Copy code
  1. <template>
  2. <div class="container">
  3. <div class="item-container">
  4. <text>{{hasInstalled}}</text>
  5. <input type="button" class="btn" onclick="pkgHasInstalled" value="pkgHasInstalled" />
  6. </div>
  7. <div class="item-container">
  8. <input type="button" class="btn" onclick="pkgInstall" value="installPkg" />
  9. </div>
  10. <div class="item-container">
  11. <text>{{versionInfo}}</text>
  12. <input type="button" class="btn" onclick="pkgGetInfo" value="getPkgInfo" />
  13. </div>
  14. <div class="item-container">
  15. <text>{{signatures}}</text>
  16. <input type="button" class="btn" onclick="pkgGetSignatureDigests" value="getPkgSignatureDigests" />
  17. </div>
  18. </div>
  19. </template>
  20. <style>
  21. .container{
  22. flex: 1;
  23. flex-direction: column;
  24. }
  25. .item-container {
  26. margin-top: 50px;
  27. margin-right: 60px;
  28. margin-left: 60px;
  29. flex-direction: column;
  30. }
  31. .btn {
  32. height: 80px;
  33. text-align: center;
  34. border-radius: 5px;
  35. margin-right: 60px;
  36. margin-left: 60px;
  37. margin-bottom: 50px;
  38. color: #ffffff;
  39. font-size: 30px;
  40. background-color: #0faeff;
  41. }
  42. </style>
  43. <script>
  44. import pkg from '@system.package'
  45. import prompt from '@system.prompt'
  46. export default {
  47. data: {
  48. versionInfo: '',
  49. signatures: '',
  50. hasInstalled:''
  51. },
  52. onInit: function () {
  53. this.$page.setTitleBar({ text: 'package' })
  54. },
  55. pkgHasInstalled: function () {
  56. let that = this
  57. pkg.hasInstalled({
  58. package: 'com.huawei.appmarket',
  59. success: function (data) {
  60. console.log('handling success: ' + data.result);
  61. that.hasInstalled = data.result;
  62. prompt.showToast({
  63. message: 'result---' + data.result
  64. })
  65. },
  66. fail: function (erromsg, errocode) {
  67. prompt.showToast({ message: "hasInstalled fail" + errocode + ': ' + erromsg })
  68. },
  69. complete: function () {
  70. console.log('complete')
  71. }
  72. })
  73. },
  74. pkgInstall: function () {
  75. pkg.install({
  76. package: 'com.sina.news',
  77. success: function (data) {
  78. console.log('handling success: ' + data.result)
  79. prompt.showToast({
  80. message: 'success'
  81. })
  82. },
  83. fail: function (data, code) {
  84. console.log('handling fail, code=' + code)
  85. prompt.showToast({
  86. message: 'fail'
  87. })
  88. },
  89. complete: function () {
  90. console.log('pkg install complete')
  91. }
  92. })
  93. },
  94. pkgGetInfo: function () {
  95. var that = this
  96. pkg.getInfo({
  97. package: 'com.huawei.appmarket',
  98. success: function (ret) {
  99. console.log('getInfo succ data:' + JSON.stringify(ret))
  100. that.versionInfo = JSON.stringify(ret)
  101. prompt.showToast({
  102. message: 'succ! versionCode:' + ret.versionCode + '\n versionName:' + ret.versionName
  103. })
  104. },
  105. fail: function (erromsg, errocode) {
  106. that.versionInfo = errocode + ': ' + erromsg
  107. prompt.showToast({ message: "get pkginfo fail" + errocode + ': ' + erromsg })
  108. },
  109. complete: function () {
  110. console.log('complete')
  111. }
  112. })
  113. },
  114. pkgGetSignatureDigests: function () {
  115. var that = this
  116. pkg.getSignatureDigests({
  117. package: 'com.huawei.appmarket',
  118. success: function (ret) {
  119. console.log('getSignatureDigests succ data:' + JSON.stringify(ret))
  120. that.signatures = JSON.stringify(ret)
  121. prompt.showToast({
  122. message: 'succ!' + 'sing:\n' + ret.signatures
  123. })
  124. },
  125. fail: function (erromsg, errocode) {
  126. that.signatures = errocode + ': ' + erromsg
  127. prompt.showToast({ message: "GetSignatureDigests fail" + errocode + ': ' + erromsg })
  128. },
  129. complete: function () {
  130. console.log('complete')
  131. }
  132. })
  133. }
  134. }
  135. </script>

The following figure shows the final effect.

Version Change History

Expand

Version

Date

Description

1070

2020-05-19

  • Added the getInfo method to obtain the app version code and name.
  • Added the getSignatureDigests method to obtain app signature digests.
Search in References
Enter a keyword.