Trying to get the DeepLinks or DynamicLinks to work on Android.
Not sure if this is an issue or just my configuration & usage. But I have noticed that the issue is the same on a pair of plugins trying to do the same (firebase plugin and url-handler).
When listening to the activityResumedEvent on Android, the getAction() & getData() return null. Even tho the ActivityManager logs the new intent with all the data.
This is my intent config:
<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="myurl"/>
<data android:scheme="https"/>
<data android:scheme="http"/>
</intent-filter>
Also added this to my main activity android:launchMode="singleTask"
Code in app.ts:
application.android.on(application.AndroidApplication.activityResumedEvent, (args: application.AndroidActivityEventData) => {
var intentData = args.activity.getIntent().getData();
console.log("------>>>>>> IntentAction: " + args.activity.getIntent().getAction());
console.log("------>>>>>> IntentData: " + intentData);
});
So when trying to open a dynamicLink from another app, the app opens, but the intent data is null, so we cannot fetch the url and parse it.
ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://XXXXX.app.goo.gl/... flg=0x3000000 cmp=com.myapp/com.tns.NativeScriptActivity (has extras)} from uid 10070
JS: ------>>>>>> IntentAction: null
JS: ------>>>>>> IntentData: null
Android
Hi @manijak,
Thank you for contacting us,
I tested your case and found that you could get the data from the intent while using getStringExtra and getIntExtra methods. For your convenience, I am attaching sample project, where it is demonstrated the usage of the methods mentioned above.
Archive.zip
Also, I requested opening the app while using the following piece of code:
var intent = context.getPackageManager().getLaunchIntentForPackage(appID);
intent.putExtra("test", "testvalue");
intent.putExtra("testInt", 11)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Hope this helps.
Hi @tsonevn, thanks for the example and code, but this does not solve our problem.
Keep in mind that when using DeepLinks we have no control of the activity or the intent and its contents. These links are opened usually from another app, like Twitter, Facebook or SMS. So they start the activity and based on the app-id, it launches the app with specific activity and data.
From what I've seen, neither the activityResumedEvent or the activityCreatedEvent are able to return these values...
Update, activityResumedEvent does indeed return these values, but only if the app is started from suspend mode! Question is, why doesn't the same event (activityResumedEvent) return these values while the app is running? I must be doing something wrong here...
The way I'm testing this is by tapping a deepLink from the SMS app in the emulator or email-app on a device.
1) App running in background (resumed event only returns MAIN action, not VIEW for some reason...):
ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://fjb7h.app.goo.gl/... cmp=ba.fkzeljeznicar/com.tns.NativeScriptActivity (has extras)} from uid 10070
JS: ------>>>>>> (activityResumedEvent) action: android.intent.action.MAIN
JS: ------>>>>>> (activityResumedEvent) data: null
JS: ------>>>>>> (activityResumedEvent) extras: null
2) App not running (suspended):
ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://fjb7h.app.goo.gl/... cmp=ba.fkzeljeznicar/com.tns.NativeScriptActivity (has extras)} from uid 10070
JS: ------>>>>>> (activityResumedEvent) action: android.intent.action.VIEW
JS: ------>>>>>> (activityResumedEvent) data: https://fjb7h.app.goo.gl/30536
JS: ------>>>>>> (activityResumedEvent) extras: Bundle[{com.android.browser.application_id=com.google.android.apps.messaging}]
Hi @manijak,
Could you make the needed changes in the application which I attached in my first comment, to demonstrate, how you are taking the data from the intent?
Also provide the deep link structure, which is used in the email or SMS.
I tested the different scenarios, while the app is running or it is suspended. However, I am still unable to recreate the issue.
Thank you in advance for the cooperation.
@tsonevn,
From the looks of it, the difference is that I used android:launchMode="singleTask" on the activity in the manifest file, instead of the default standard. I wanted a single instance of my app, not multiple... read somewhere that when adding the new intent-filter, the launchMode should be singleTask or singleInstance.
Ok so, in the scenario where a user is launching the app via a DeepLink from another app (keeping in mind that the app could already be running in the background, e.g. launched normally earlier).
If the app has android:launchMode="standard" or android:launchMode="singleTop"
activityResumedEvent will provide the passed intentData and Action.If the app has android:launchMode="singleTask" or android:launchMode="singleInstance"
activityResumedEvent will not pass intentData & Action if the app is already running. If the app is launching for the first time, the intentData and action are passed. I've noticed strange things in my app when it's launched with multiple instances (say, once from the app drawer and the second via a deeplink from the sms app). The original app becomes unresponsive in certain areas (e.g. tap doesn't work in listView). Not to mention that the user can see two instances of my app when opening the "Overview", very confusing.
Here is the modified app you provided earlier:
Archive2.zip
Don't get me wrong regarding the above "pros/cons", I think this is just the way Android works and is intended to work. Also think it would be good (for my own sanity) if the {N} experts cloud just confirm that this is the way Intents and events work. At least there will be a nice explanation for others when they stumble upon this.
Just find it weird when using standard launchMode, that the e.g. SMS app "becomes" my-app, like it's launched innside the SMS activity or something. So when the user goes to the homescreen, and taps the SMS app icon, whoops, my-app is shown, not SMS. Very confusing... That's why I think singleTask/Instance would be more correct to use in this case.
But when it comes to the multiple instances of the same app, in combination with page-navigation, there is for sure an issue here. I have managed to reproduce it, and could post a separate issue regarding that. When there are two instances of the app, navigation events are not registered in the original app instance. They are just passed to the other (new) instance.
Hi @manijak,
There's a big chance this PR fixes your issue. You can test it out by installing the tns-core-modules from next although, I'm not sure they're compatible with your project.
Another alternative is to temporary do the fix provided in the PR locally and try to build.
@Plamen5kov, Thanks for the tip. This looks promissing. I implemented the code in my app and also the demo app from @tsonevn and tested.
On the demo-app, I tried installing the @next version of tns-core-modules. I checked that the new onNewIntent code was added. But when running the app, it seems like no events are hit. Could be something else in the modules that is causing this. But I did not get any hit in the new onNewIntent event, nor the existing activityResumedEvent.... strange. Delete the entire hooks, platforms, node_modules prior to test.
Decided then to test on my app, but without installing the @next version of modules. Just added the new function manually in the activity.android.js file, and ran the app. This time it worked!
The events are hit, and I get the needed data in the activityResumedEvent also 馃憤 all this with single instance of my app.
Thanks for your help guys!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@Plamen5kov, Thanks for the tip. This looks promissing. I implemented the code in my app and also the demo app from @tsonevn and tested.
On the demo-app, I tried installing the
@nextversion of tns-core-modules. I checked that the newonNewIntentcode was added. But when running the app, it seems like no events are hit. Could be something else in the modules that is causing this. But I did not get any hit in the newonNewIntentevent, nor the existingactivityResumedEvent.... strange. Delete the entire hooks, platforms, node_modules prior to test.Decided then to test on my app, but without installing the
@nextversion of modules. Just added the new function manually in the activity.android.js file, and ran the app. This time it worked!The events are hit, and I get the needed data in the
activityResumedEventalso 馃憤 all this with single instance of my app.Thanks for your help guys!