Notification Tap-to-Redirect

Last updated: 2020-11-09 11:37:51

    Overview

    You can redirect subscribers who tap your notification to the specified in-app page, HTML5 page and Deeplink to meet your needs in different use cases.

    Scope

    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 application by default
  • The business logic is based on the passed-in custom key and value
  • Android Applications

    Note:

    In the SDK, a tap on a message can trigger a click event by default, which opens the target page. If a redirect action is configured in onNotifactionClickedResult, it will conflict with the custom redirect rule specified in the console/API, and the custom redirect rule will fail.

    Configuring SDK

    To use Intent redirect, first configure the page to be redirected to in the client application’s AndroidManifest file.

    If you want to redirect to the page specified by AboutActivity, use the following sample code:

    <activity
        android:name="com.qq.xg.AboutActivity"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter >
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT"/>
            <!-- The custom data block specifies your complete scheme, which will generate a URL in the format of "scheme name://hostname/pathname" based on your configuration -->
            <!-- You may use application name, application package name, or another field that uniquely identifies the application to avoid conflicting redirection with other applications-->
            <data
                  android:scheme="Scheme name"
                  android:host="Hostname"
                  android:path="/Path name" />
        </intent-filter>
    </activity>

    Using the console

    Intent redirect (recommended)

    To set the Intent redirect on the TPNS Console, go to Advanced Settings -> Open Location and enter the following information.

    Opening application

    Tapping on the notification that is pushed via the console will open the application by default.

    URL redirect

    To set the URL redirect on the TPNS Console, go to Advanced Settings -> Open Location and enter the following information.

    In-app Activity redirect

    This method will be deactivated, so we don’t recommend using it. Go to Advanced Settings -> Open Location in the console and enter the following information.

    Using RESTful APIs

    Add the action and action_type fields under body.message.android of the push message body.

    Field Name Type Parent Item 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 application.
    action_type Integer Action 1 No One-tap action. Valid values:
  • 1: opens Activity or application
  • 2: opens the browser
  • 3: Opens Intent (recommended; for more information, see Configuring SDK)
  • Intent redirect (recommended)

    Below is a sample of a complete message:

    {
      "audience_type": "token",
      "token_list": [
          "04xxx993"
      ],
       "message_type": "notify",
        "message":{
        "title": "xxx",
        "content": "xxx",
        "android": {
          "action": {
                "action_type": 3,// Action type; 1. Open Activity or application; 2. Open browser; 3. Open Intent          
                "intent": "xgscheme://com.xg.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
            }
          }
       }    
    }

    If you want to pass in custom parameters such as 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. Open Activity or application; 2. Open browser; 3. Open Intent          
                "intent": "xgscheme://com.xg.push/notify_detail?param1=aa&param2=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
            }
          }
       }
    }

    Note:

    If the client requires more parameters for other responses, refer to Getting parameters on the client.

    Opening application

    Below is a sample of a complete message:

    {
      "audience_type": "token",
      "token_list": [
          "04xxx993"
      ],
       "message_type": "notify",
        "message":{
        "title": "xxx",
        "content": "xxx",
        "android": {
          "action": {
               "action_type": 1,// Action type; 1. Open Activity or application; 2. Open browser; 3. Open Intent  
            }
          }
       }    
    }

    URL redirect

    Below is a sample of a complete message:

    {
      "audience_type": "token",
      "token_list": [
          "04xxx993"
      ],
       "message_type": "notify",
        "message":{
        "title": "xxx",
        "content": "xxx",
        "android": {
          "action": {
               "action_type": 2,// Action type; 1. Open Activity or application; 2. Open browser; 3. Open Intent          
               "browser": {
                    "url": "http://tpns.qq.com", // Only http and https are supported
                    "confirm": 1 // Whether user’s confirmation is required
                }
            }
          }
       }
    }

    Opening the in-app Activity

    Below is a sample of a complete message:

    {
      "audience_type": "token",
      "token_list": [
          "04xxx993"
      ],
       "message_type": "notify",
        "message":{
        "title": "xxx",
        "content": "xxx",
        "android": {
          "action": {
               "action_type": 1,// Action type; 1. Open Activity or application; 2. Open browser; 3. Open 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
                    }
                }
            }
        }
    }

    Getting parameters on the client

    1. In the onCreate method of the page you specify for redirect to, add the following code:

      Uri uri = getIntent().getData();
      if (uri != null) {                
           String url = uri.toString();
           String p1= uri.getQueryParameter("param1");
           String p2= uri.getQueryParameter("param2");
      }
    2. If the parameters passed in contain special characters such as # and &, you can parse them using the following method:

      Uri uri = getIntent().getData();
      if (uri != null) {                
           String url = uri.toString();
           UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
           sanitizer.setUnregisteredParameterValueSanitizer(UrlQuerySanitizer.getAllButNulLegal());
           sanitizer.parseUrl(url);
           String value1 = sanitizer.getValue("key1");
           String value2 = sanitizer.getValue("key2");
           Log.i("XG" , "value1 = " + value1 + " value2 = " + value2);
      }

    iOS Applications

    You can pass in custom parameters in the notification for delivery, and implement the redirect or other business logic by parsing the parameters obtained on the client.

    Using the console

    To set parameters on the TPNS Console, go to Advanced Settings -> Extra Parameter(s) and enter the following information.

    Using RESTful APIs

    Add the following custom_content field under body.message.ios of the push message body.

    Field Name Type Parent Project Default Value Required Parameter Description
    custom_content String ios Empty No Parameters for custom delivery, which must be serialized to a JSON string.

    Below is a sample of a complete message:

    {
        "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\"}",
            }
        }
    }

    Getting parameters on the client

    If you use iOS SDK integration, you can obtain custom parameters using click callback. This callback applies to the notification messages of the app in foreground, background and shutdown status.

    /// 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 versions
            NSLog(@"notification dic: %@", ((UNNotificationResponse *)response).notification.request.content.userInfo);
        } else if ([response isKindOfClass:[NSDictionary class]]) {
            /// Getting messages on iOS versions earlier than 10
            NSLog(@"notification dic: %@", response);
        }
        completionHandler();
    }

    If you use Flutter plugin integration, use the following APIs in the runner->AppDelegate->didFinishLaunchingWithOptions method at cold startup to:

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
        {
                // Get message content
                NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
                // Process logically based on the message content
        }

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help