Notification-Click Redirection

Last updated: 2021-08-17 16:08:37

    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"/>
           <!-- Specify your complete scheme by customizing the content of the data block. According to your configuration, a URL identifier in the format of "semantic name://host name/path name" will be formed -->
           <!-- To avoid conflicts with the redirection destination pages of other applications, you can use fields that can uniquely identify the application for configuration, such as those with the application name or application package name -->
           <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 in 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 in 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 an 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.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
          }
        }
     }    
    }
    

    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.tpns.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 onCreatemethod of the page you specify for redirect to, add the following intent URI code:
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_temp)
      ;

      // ...

      // Obtain the intent URI code in `onCreate`
      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");
      }

      // ...
      }
    2. If your Activity page is the application's resident page (for example, 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:
      java
      @Override
      protected void onNewIntent(Intent intent) {
      super.onNewIntent(intent);

      // ...

      // Get the intent URI code in `onNewIntent`
      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");
      }

      // ...
      }

    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 in 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 get parameters:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    {
            // Get the message content.
            NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
            // Perform logical processing according to the message content.
    }