Deep Linking

MessagingSDK allows for Push Notifications to contain a link to a section inside of the Application or to a Web Page link.

For this we have 3 modalities:

  • Payload

  • URL Schema

  • Universal Links

Payload

The "click_action" property sent through the Push Notification will be used, which has two cases:

  1. Notification in Foreground: handled by the SDK

  2. Notification in Background: handled by the OS

Notification in Foreground

The Notification will be handled by the SDK taking the property "click_action", which should have a value as shown in the example:

"click_action": "com.ogangi.Messangi.SDK.Demo.ExampleActivity "

This is then processed by the SDK, allowing the host app to create an icon in the notification tray that when the user opens the activity it executes the defined action.

The declaration of the activity must be done in the AndroidManifest.xml file:

<activity android: name = ".ExampleActivity">
            <intent-filter>
            <action android: name = "com.ogangi.Messangi.SDK.Demo.ExampleActivity" />
            <category android: name = "android.intent.category.DEFAULT" />
            </intent-filter>
       </activity>

In MainActivity of the Demo App, a Foreground Notification is sent:

image2.jpg

Arrival of the Push Notification to the App that shows the detail of the Notification and in the upper part, it displays the generation of the Notification due to theClick-Actionparameter. To generate the notification you can see thelaunchNotification method in MainActivity of the Demo app.

Then open the notification palette:

image1.jpg

When the Notification is clicked and is opened, the predetermined activity is executed and data is obtained with the following structure:

Bundle extras=getIntent().getExtras();
       boolean enable=extras.getBoolean("enable",false);
       additionalData = new HashMap<>();
       if(extras!=null && !enable) {
           for (String key : extras.keySet()) {
              additionalData.put(key, extras.getString(key));
               messangiData.add(key + " , " + extras.getString(key));
           }
           .....
       }else{
           Serializable data = extras.getSerializable(Messaging.INTENT_EXTRA_DATA);
           messagingNotification=(MessagingNotification)data;
           additionalData=messagingNotification.getAdditionalData();
           if(additionalData!=null&& additionalData.size()>0) {
               messangiData.add("Title: " + messagingNotification.getTitle());
               messangiData.add("Body: " + messagingNotification.getBody());
               messangiData.add("ClickAction: " + messagingNotification.getClickAction());
               messangiData.add("DeepUriLink: " + messagingNotification.getDeepUriLink());
               for (Map.Entry entry : messagingNotification.getAdditionalData().entrySet()) {
                   if (!entry.getKey().equals("profile")) {
                       messangiData.add(entry.getKey() + " , " + entry.getValue());
                   }

               }
           }
       }
       .....
image17.jpg

Finally the screen of the open activity is presented as a product of the parameter"Click_Action"

" click_action ":" com.ogangi.Messangi.SDK.Demo.ExampleActivity

Notification in Background

In this case, the Notification will be handled by the OS with its native behavior.

The activity when the Notification is opened by the user must be declared, it is important to remember that the Notification must contain the field:

" click_action ":"com.ogangi.Messangi.SDK.Demo.ExampleActivity "

Then open the notification palette:

image1.jpg
image10.jpg

Finally the screen of the open activity is presented as a product of the parameter"Click_Action"

This action was performed using the OS native behavior, but it is important that the Notification contains the "click_action" field:

"com.ogangi.Messangi.SDK.Demo.ExampleActivity"

The obtained data can also be processed using the following code in ExampleActivity.class:

Bundle extras=getIntent().getExtras();
       boolean enable=extras.getBoolean("enable",false);
       additionalData = new HashMap<>();
       if(extras!=null && !enable) {
           for (String key : extras.keySet()) {
              additionalData.put(key, extras.getString(key));
               messangiData.add(key + " , " + extras.getString(key));
           }
           .....
       }else{
           Serializable data = extras.getSerializable(Messaging.INTENT_EXTRA_DATA);
           messagingNotification=(MessagingNotification)data;
           additionalData=messagingNotification.getAdditionalData();
           if(additionalData!=null&& additionalData.size()>0) {
               messangiData.add("Title: " + messagingNotification.getTitle());
               messangiData.add("Body: " + messagingNotification.getBody());
               messangiData.add("ClickAction: " + messagingNotification.getClickAction());
               messangiData.add("DeepUriLink: " + messagingNotification.getDeepUriLink());
               for (Map.Entry entry : messagingNotification.getAdditionalData().entrySet()) {
                   if (!entry.getKey().equals("profile")) {
                       messangiData.add(entry.getKey() + " , " + entry.getValue());
                   }

               }
           }
       }

Url Schema

The "link" property sent through the Push Notification will be used, which has two cases:

  1. Notification in Foreground: handled by the SDK

  2. Notification in Background: handled by the OS

Notification in Foreground

The Notification will be handled by the SDK taking the property "link", which should have a value as shown in the example:

"link": "exampleapp://example/example?param1=1"

This is then processed by the SDK, allowing the host app to open the activity and take the data that brings the push notification.To open the Activity you can see the launchBrowser method in MainActivity of the Demo app.

The declaration of the activity must be done in the AndroidManifest.xml file:

<activity android: name = ".ExampleURLSchemasActivity">
            <intent-filter>
             <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="example"
                    android:pathPrefix="/example"
                    android:scheme="exampleapp" />
             </intent-filter>
       </activity>
	

In MainActivity of the Demo App, a Foreground Notification is sent:

image4.jpg

after the push notification is sent, the activity ExampleURLSchemasActivity will open automatically:

image9.jpg
Notification in Background

In this case, the Notification will be handled by the OS with its native behavior.

The activity when the Notification is opened by the user must be declared, it is important to remember that the Notification must contain the field:

"link":"exampleapp://example/example?param1=1"

Then open the notification palette:

image1.jpg

after clicking on the notification, the following Activity will open:

image9.jpg

The obtained data can also be processed using the following code in ExampleURLSchemasActivity.class:

Bundle extras=getIntent().getExtras();
       boolean enable=extras.getBoolean("enable",false);
       additionalData = new HashMap<>();
       if(extras!=null && !enable) {
           for (String key : extras.keySet()) {
              additionalData.put(key, extras.getString(key));
               messangiData.add(key + " , " + extras.getString(key));
           }
           .....
       }else{
           Serializable data = extras.getSerializable(Messaging.INTENT_EXTRA_DATA);
           messagingNotification=(MessagingNotification)data;
           additionalData=messagingNotification.getAdditionalData();
           if(additionalData!=null&& additionalData.size()>0) {
               messangiData.add("Title: " + messagingNotification.getTitle());
               messangiData.add("Body: " + messagingNotification.getBody());
               messangiData.add("ClickAction: " + messagingNotification.getClickAction());
               messangiData.add("DeepUriLink: " + messagingNotification.getDeepUriLink());
               for (Map.Entry entry : messagingNotification.getAdditionalData().entrySet()) {
                   if (!entry.getKey().equals("profile")) {
                       messangiData.add(entry.getKey() + " , " + entry.getValue());
                   }

               }
           }
       }

Universal Link

The "link" property sent through the Push Notification will be used, which has two cases:

  1. Notification in Foreground: handled by the SDK

  2. Notification in Background: handled by the OS

Notification in Foreground

The Notification will be handled by the SDK taking the property "link", which should have a value as shown in the example:

"link": "http://www.plantplaces.com/colorcapture.shtml?param1=value1&param2=value2"

This is then processed by the SDK, allowing the host app to open the activity and take the data that brings the push notification.To open the Activity you can see the launchBrowser method in MainActivity of the Demo app.

The declaration of the activity must be done in the AndroidManifest.xml file:

<activity android: name = ".ExampleUrlActivity">
            <intent-filter>
             <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data                       android:host="www.plantplaces.com"                    android:pathPrefix="/colorcapture.shtml"                    android:scheme="http" />
             </intent-filter>
       </activity>

In MainActivity of the Demo App, a Foreground Notification is sent:

image16.jpg

after the push notification is sent, the app demo will open automatically by selection,

the the activityExampleUrlActivity will open:

image13.jpg

The obtained data can also be processed using the following code in ExampleURLActivity.class:

Bundle extras=getIntent().getExtras();
       boolean enable=extras.getBoolean("enable",false);
       additionalData = new HashMap<>();
       if(extras!=null && !enable) {
           for (String key : extras.keySet()) {
              additionalData.put(key, extras.getString(key));
               messangiData.add(key + " , " + extras.getString(key));
           }
           .....
       }else{
           Serializable data = extras.getSerializable(Messaging.INTENT_EXTRA_DATA);
           messagingNotification=(MessagingNotification)data;
           additionalData=messagingNotification.getAdditionalData();
           if(additionalData!=null&& additionalData.size()>0) {
               messangiData.add("Title: " + messagingNotification.getTitle());
               messangiData.add("Body: " + messagingNotification.getBody());
               messangiData.add("ClickAction: " + messagingNotification.getClickAction());
               messangiData.add("DeepUriLink: " + messagingNotification.getDeepUriLink());
               for (Map.Entry entry : messagingNotification.getAdditionalData().entrySet()) {
                   if (!entry.getKey().equals("profile")) {
                       messangiData.add(entry.getKey() + " , " + entry.getValue());
                   }

               }
           }
       }
Notification in Background

In this case, the Notification will be handled by the OS with its native behavior.

The activity when the Notification is opened by the user must be declared, it is important to remember that the Notification must contain the field:

"link":"http://www.plantplaces.com/colorcapture.shtml?param1=value1&param2=value2"

Then open the notification palette:

image1.jpg

after clicking on the notification, the following Activity will open:

image6.jpg

The obtained data can also be processed using the following code in ExampleURLActivity.class:

Bundle extras=getIntent().getExtras();
       boolean enable=extras.getBoolean("enable",false);
       additionalData = new HashMap<>();
       if(extras!=null && !enable) {
           for (String key : extras.keySet()) {
              additionalData.put(key, extras.getString(key));
               messangiData.add(key + " , " + extras.getString(key));
           }
           .....
       }else{
           Serializable data = extras.getSerializable(Messaging.INTENT_EXTRA_DATA);
           messagingNotification=(MessagingNotification)data;
           additionalData=messagingNotification.getAdditionalData();
           if(additionalData!=null&& additionalData.size()>0) {
               messangiData.add("Title: " + messagingNotification.getTitle());
               messangiData.add("Body: " + messagingNotification.getBody());
               messangiData.add("ClickAction: " + messagingNotification.getClickAction());
               messangiData.add("DeepUriLink: " + messagingNotification.getDeepUriLink());
               for (Map.Entry entry : messagingNotification.getAdditionalData().entrySet()) {
                   if (!entry.getKey().equals("profile")) {
                       messangiData.add(entry.getKey() + " , " + entry.getValue());
                   }

               }
           }
       }
	

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.