Platform | Type |
Android | Intent redirect: jumps to the specified in-app page. You can also pass in custom parameters. Open application: directly goes to the application’s homepage. URL: opens the browser and accesses the specified webpage. In-app activity: jumps to the specified in-app page. |
iOS | Opens the app by default. Implements the business logic based on the delivered custom key and value. |
onNotifactionClickedResult
, it will conflict with the custom redirect rule specified in the console or API, and the custom redirect rule will fail.AndroidManifest
file.AboutActivity
, use the following sample code:<activityandroid:name="com.qq.xg.AboutActivity"android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ><!-- Other intent-filter --><!-- <intent-filter> ... </intent-filter> --><!-- AndroidManifest supports configuring multiple intent-filters for an Android component. Please add the custom redirection configuration in a separate intent-filter. --><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT"/><!-- Customize the content of the data block to specify your complete scheme. --><!-- According to your configuration, a URL in the `scheme name://host name/path name` format will be formed. --><!-- To avoid conflicts with the redirection destination pages of other apps, you are advised to use fields that can uniquely identify the app for configuration, such as those with the app name or app package name. --><dataandroid:scheme="Scheme name"android:host="Host name"android:path="/Path name" /></intent-filter></activity>
action
and action_type
fields under body.message.android
of the push message body.Field | Type | Parent Project | Default Value | Required | Description |
action | Object | Android | 1 | No | This sets the action after the notification bar is tapped; the default action is to open an application. |
action_type | Integer | Action | 1 | No | One-tap action. Valid values: 1 : opens activity or app2 : opens browser3 : opens Intent (recommended; for more information, see Configuring SDK) |
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 3, // Action type. `1`: opens activity or app; `2`: opens browser; `3`: opens Intent"intent": "xgscheme://com.tpns.push/notify_detail" // The SDK must be version 1.0.9 or later. Configure the data tag in the client's Intent and set the scheme attribute}}}}
param1
and param2
, use the sample code below:{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 3, // Action type. `1`: opens activity or app; `2`: opens browser; `3`: opens Intent"intent": "xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb" // The SDK must be version 1.0.9 or later. Configure the data tag in the client's Intent and set the scheme attribute}}}}
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 1 // Action type. `1`: opens activity or app; `2`: opens browser; `3`: opens Intent}}}}
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 2, // Action type. `1`: opens activity or app; `2`: opens browser; `3`: opens Intent"browser": {"url": "http://tpns.qq.com", // Only HTTP and HTTPS URLs are supported"confirm": 1 // Whether user's confirmation is required}}}}}
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 1, // Action type. `1`: opens activity or app; `2`: opens browser; `3`: opens Intent"activity": "com.x.y.MainActivity","aty_attr": {// Activity attribute, only for action_type=1"if": 0, // Intent's Flag attribute"pf": 0 // PendingIntent's Flag attribute}}}}}
onCreate
method of the page you specify for redirect, add the following intent URI code:@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_temp);// ...// Getting parameters via `onCreate`// If the `intent uri` (client customization) mode is used for push, and parameters are added to the end of `intent`, you can use this code snippet to get the parameter values.// For example, if the value of the pushed `intent` is `xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb`,// you can use this code snippet to get the values of `param1` and `param2`, which are `aa` and `bb` respectively.Uri uri = getIntent().getData();Log.i(TAG, "onCreate get data uri: " + uri);if (uri != null) {String url = uri.toString();String p1 = uri.getQueryParameter("param1");String p2 = uri.getQueryParameter("param2");}// This is new from SDK 1.3.2.0.// If `custom_content` is set when the push task is created, you can use this API to get the content of the `custom_content` string.String customContent = XGPushManager.getCustomContentFromIntent(this, this.getIntent());// ...}
launchMode
is set to singleTop
or singleTask
), the intent content for tap-to-redirect will be triggered by the onNewIntent
method of the activity page. Please add the following to the onNewIntent
method to get the intent URI code:@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);// ...// Getting parameters via `onNewIntent`// If the `intent uri` (client customization) mode is used for push, and parameters are added to the end of `intent`, you can use this code snippet to get the parameter values.// For example, if the value of the pushed `intent` is `xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb`,// you can use this code snippet to get the values of `param1` and `param2`, which are `aa` and `bb` respectively.Uri uri = intent.getData();Log.i(TAG, "onNewIntent get data uri: " + uri);if (uri != null) {String url = uri.toString();String p1 = uri.getQueryParameter("param1");String p2 = uri.getQueryParameter("param2");}// This is new from SDK 1.3.2.0.// If `custom_content` is set when the push task is created, you can use this API to get the content of the `custom_content` string.String customContent = XGPushManager.getCustomContentFromIntent(this, intent);// ...}
Uri uri = getIntent().getData();if (uri != null) {String p1 = uri.getQueryParameter("param1");String value1 = "";try {// The value of the custom parameter `param1` contains special characters. You can use URLEncode to encode it when creating the push and use URLDecode to decode it when obtaining it.value1 = URLDecoder.decode(p1, "UTF-8");} catch (UnsupportedEncodingException e) {Log.w("TPNS", "URLDecode param failed: " + e.toString());}// The custom parameter `param2` is not encoded with URLEncode and can be obtained directly.String value2 = uri.getQueryParameter("param2");Log.i("TPNS" , "value1 = " + value1);}
custom_content
field under body.message.ios
of the push message body.Field | Type | Parent Project | Default Value | Required | Description |
custom_content | String | ios | Empty | No | Custom parameter for delivery, which must be serialized to a JSON string. |
{"audience_type": "token","environment": "dev","token_list": ["0250df875c93c555dd3a2ba536b54fc1xxxx"],"message_type": "notify","message": {"title": "xxx","content": "xxxxxxxxx","ios":{"aps": {"alert": {"subtitle": "xxx"}},"custom_content": "{\\"key\\":\\"value\\"}"}}}
/// Unified message click callback/// @param response will be `UNNotificationResponse` for iOS 10+/macOS 10.14+, or `NSDictionary` for earlier versions./// @note TPNS SDK1.2.7.1+- (void)xgPushDidReceiveNotificationResponse:(nonnull id)response withCompletionHandler:(nonnull void (^)(void))completionHandler {NSLog(@"[XGDemo] click notification");if ([response isKindOfClass:[UNNotificationResponse class]]) {/// Getting messages on iOS 10 or later versionsNSLog(@"notification dic: %@", ((UNNotificationResponse *)response).notification.request.content.userInfo);} else if ([response isKindOfClass:[NSDictionary class]]) {/// Getting messages on iOS versions earlier than 10NSLog(@"notification dic: %@", response);}completionHandler();}
Was this page helpful?