Laws such as the Personal Information Protection Law, the Data Security Law, and the Cybersecurity Law require application developers and operators (developers) to respect and protect the personal information of end users. You must not illegally collect or use personal information when you provide online products and services. This guide helps you use the Mobile Push software development kit (SDK) in compliance with these requirements and protect the rights of your end users.
Mobile Push SDK system permission requests
Permission | Required | Purpose |
INTERNET | Yes | The basic permission that allows the SDK to connect to the network. It is used to establish a persistent connection and enable the push feature. |
GET_NETWORK_INFO | Yes | Detects the network status. It is used to determine network connectivity and resume the connection when the network is restored. |
Mobile Push SDK features and related personal information
Feature | Personal information field collected | Purpose of collection | Configuration method and example |
Push feature (Basic feature) | Device identification information (phone brand, model, and OS version) | To improve the accuracy and reliability of push notifications. | Basic feature. This information is required. |
Configuration for optional personal information fields
Optional personal information field | Purpose of collection | Configuration method and example |
Phone number | To use the | Configure this feature by calling |
Compliant initialization configuration for the Mobile Push SDK
/**
* Push SDK interface
*/
export interface IPushService {
/**
* Initializes the configuration.
* @param config
*/
init(config: PushConfig): void;
/**
* Establishes a connection and registers the device.
* You must ensure that the user agrees to the Privacy Policy before you call the register(...) method.
* @param callback
*/
register(callback: AsyncCallback): void;
register(): Promise<void>;
}The aliyunPush.init(...) method can be called before the user agrees to the Privacy Policy.
You must ensure that the user agrees to the Privacy Policy before you call the aliyunPush.register(...) method.
Code example
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
import {
aliyunPush,
BasePushData,
Channel,
IPushListener,
PushMessage,
PushNotification,
PushNotificationHandler
} from '@aliyun/push';
import { pushService } from '@kit.PushKit';
/**
* Custom implementation of the push callback interface.
*/
class MyPushListener implements IPushListener {
onReceiveNotification(data: PushNotification): boolean {
// Process push notifications.
return false;
}
onShowNotification(data: PushNotification): void {
// Process notification display events.
}
onReceiveMessage(data: PushMessage): void {
// Process push messages.
}
}
/**
* Custom class for processing push data.
*/
class MyPushNotificationHandler implements PushNotificationHandler {
onClickNotification(data: PushNotification | BasePushData, from: Channel): void {
// On the page opened by a user clicking a notification, get the push data and process business logic.
}
noPushData(): void {
// The page was not opened by a user clicking a notification.
}
}
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// ************* Initialize the SDK: start *************
aliyunPush.init({
appKey: 'Enter the AppKey that you obtained in the Preparations step',
appSecret: 'Enter the AppSecret that you obtained in the Preparations step',
context: this.context,
})
// ************* Initialize the SDK: end *************
// ************* Set the push callback interface: start *************
aliyunPush.setPushListener(new MyPushListener());
// ************* Set the push callback interface: end *************
// ************* Call the notification click processing interface: start *************
aliyunPush.handleClickNotification(want, new MyPushNotificationHandler())
// ************* Call the notification click processing interface: end *************
// Save the user's consent to the privacy policy locally. If the user has consented, call the register method during initialization.
if(hasSignedAgreement) {
this.registerPush();
} else {
// If the user has not consented, call the register method after they provide consent.
}
}
private async registerPush() {
// ************* Register the device and get the device ID: start *************
await aliyunPush.register();
const deviceId = aliyunPush.getDeviceId();
// ************* Register the device and get the device ID: end *************
const pushToken = await pushService.getToken();
// ************* Register the HarmonyOS PushToken: start *************
await aliyunPush.registerThirdToken(pushToken);
// ************* Register the HarmonyOS PushToken: end *************
}
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// ************* Call the notification click processing interface: start *************
aliyunPush.handleClickNotification(want, new MyPushNotificationHandler())
// ************* Call the notification click processing interface: end *************
}
// Other code is omitted.
}