Push notification scenarios

更新时间:
复制 MD 格式

Introduction to push notification scenarios

  • Push by device ID

  • Push by account

  • Push by alias

  • Push by tag

  • Notification scenarios

    • Open an application

    • Open a specific activity

    • Open a specific webpage

    • Custom key-value pairs

  • Check device status

  • Check push results

1. Push by device ID

  • The deviceId is the unique identifier for a device in the push system. This method is often used to verify push results after the initial integration of push notifications. For more information about how to obtain the deviceId, see the Android SDK API introduction and iOS SDK API introduction.

  • In the Advanced Settings section of the console, select Specify Device. Alternatively, you can configure the push target as `DEVICE` in OpenAPI by calling `setTarget("DEVICE")`.

2. Push by account

  • For more information about setting up an account, see the interface descriptions in the SDK API documentation.

    Important

    When you push by account, all devices attached to that account receive the push notification. If you require mutually exclusive logons between accounts, you must implement this feature in your application.

  • In the Advanced Settings section of the console, select Specify Account. Alternatively, you can push by account in OpenAPI by calling `setTarget("ACCOUNT")`.

    Important

    To detach an account, call the `unbindAccount` method.

3. Push by alias

  • An alias is a nickname for a device. Attaching an alias is more flexible than attaching an account. You can add up to 128 aliases to a single device. Each alias can be up to 128 bytes long.

  • For more information about interface descriptions and call methods, see the SDK API documentation.

  • After you attach an alias, you can push notifications by alias in OpenAPI by calling `setTarget("ALIAS")` and then calling `setTargetValue()` to specify the alias.

  • You can call the `removeAlias()` method to delete a specific alias or all aliases from a device.

4. Push by tag

  • A tag is a label for a device. You can set tags as needed. You can attach tags to devices, accounts, or aliases. The system supports a maximum of 128 tags.

  • For more information about interface descriptions and call methods, see the SDK API documentation.

  • After you attach a tag, you can push notifications by tag in OpenAPI by calling `setTarget("TAG")` and then calling `setTargetValue()` to specify the tag name.

    Important

    Use the `unbindTag` method to detach a tag. Detaching a tag is not the same as deleting it. The delete feature is not currently supported.

5. Notification scenarios

  • Open an application

  • Open a specific activity

  • Open a specific webpage

  • Custom key-value pairs

5.1 Open an application

  • Tapping the notification opens the specified application. If the application is already in the foreground, no action occurs.

  • The OpenAPI settings are as follows:

    pushRequest.setAndroidOpenType("APPLICATION"); // The action to take after a notification is tapped. "APPLICATION": Opens the application. "ACTIVITY": Opens an Android activity. "URL": Opens a URL. "NONE": No action.

5.2 Open a specific activity

  • Tapping the notification opens a specific activity in the application.

  • The activity name format is `Package name` + `Activity name`. The OpenAPI settings are as follows:

    pushRequest.setAndroidOpenType("ACTIVITY"); // The action to take after a notification is tapped. "APPLICATION": Opens the application. "ACTIVITY": Opens an Android activity. "URL": Opens a URL. "NONE": No action.
    pushRequest.setAndroidActivity("com.alibaba.cloudpushdemo.bizactivity.DeviceActivity");// Sets the activity to open.
    

5.3 Open a specific webpage

  • Tapping the notification opens the specified URL in the device's default browser.

  • The OpenAPI settings are as follows:

pushRequest.setAndroidOpenType("URL"); // The action to take after a notification is tapped. "APPLICATION": Opens the application. "ACTIVITY": Opens an Android activity. "URL": Opens a URL. "NONE": No action.
pushRequest.setAndroidOpenUrl("http://www.aliyun.com");// The URL to open after an Android device receives the push notification. This parameter is valid only when androidOpenType is set to URL.

5.4 Custom key-value pairs

  • For Android, you can set `androidExtParameters` when you send a notification using OpenAPI.

pushRequest.setAndroidExtParameters("{\"key\":\"value-muting\"}");// Sets the extended properties of the notification for Android devices.
  • On the Android client, you can rewrite the notification-related methods to retrieve the `extraMap` parameter.

import com.alibaba.sdk.android.push.MessageReceiver;

protectedvoid onNotification(Context context,String title,String summary,Map<String,String> extraMap){}

protectedvoid onNotificationOpened(Context context,String title,String summary,String extraMap){}

Check the log output of the application, as shown below:

02-2915:33:11.41232577-32577/com.alibaba.push2 E/MyMessageReceiver: onNotificationOpened, title: pop title, summary: pop body.., extraMap:{"key":"value-muting"}

6. Check device status

  • You can check the status using OpenAPI. For more information, see Query device details.

  • You can check the status in the console.

7. Check push results

You can query the details of push notifications or message records for a specific time period. For more information, see Push records.