本示例向您介绍如何在应用中获取DeviceToken用于对应用的设备状态进行检测。
| Files | Last commit | Last update |
|---|---|---|
| 2 years ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago |
Device Security Kit - DeviceVerify
Overview
This sample code illustrates how to obtain a device token in an app to check the status of the app on the device.
The APIs that you need to use are packaged into @kit.DeviceSecurityKit.
Preview

How to Configure and Use
Configuring the Sample App in DevEco Studio
- Create a project. Under the project, add an app.
- Open the sample app and set bundleName in the app.json5 file to the app package name configured in AppGallery Connect.
- Enable Device status detection in AppGallery Connect. For details, please refer to here.
Using the Sample App
- Before running the sample app, connect the device to the network.
- Run the sample app. Tap GetDeviceToken to obtain the device token. If the device token is successfully obtained, it will be displayed on the page. If the device token fails to be obtained, an error code will be displayed.
Project Directory
├─entry/src/main/ets // Code area.
│ ├─entryability
│ │ └─EntryAbility.ets // Entry point class.
│ ├─model
│ │ └─DevCertManagerModel.ts // Device token obtaining class.
│ ├─pages
│ │ └─Index.ets // Home page, where a device token can be obtained.
How to Implement
Call the device token obtaining function directly on the page. To be specific, call the deviceCertificate.getDeviceToken() method to obtain a device token. For details about the source code, please refer to DevCertManagerModel.ts.
Reference
- entry\src\main\ets\entryability\EntryAbility.ets
- entry\src\main\ets\model\DevCertManagerModel.ts
- entry\src\main\ets\pages\Index.ets
Required Permissions
None
Dependencies
The device where the sample app runs must connect to the network.
Constraints
-
The sample app is only supported on Huawei phones, tablets, 2-in-1 devices, wearables and TV devices with standard systems.
-
The HarmonyOS version must be HarmonyOS NEXT Developer Beta1 or later.
-
The DevEco Studio version must be DevEco Studio NEXT Developer Beta1 or later.
-
The HarmonyOS SDK version must be HarmonyOS NEXT Developer Beta1 SDK or later.