Firebase dynamic links handled twice - android

I have a problem that firebase dynamic link is relaunched when the android app is restarted. The following sequence produces the problem:
click the deep link URL
the app is opened at the view pointed by the deep link (as expected)
close the app (completely)
open the app from the icon
the app is opened at the view pointed by the deep link (even though it should not)
after that it works fine
I am using the latest (9.0.2) libraries. The code is pretty much as in the examples (e.g. here: https://firebase.google.com/docs/dynamic-links/android#add-an-intent-filter-for-deep-links), autoLaunchDeepLink being false.
I noticed that there has been a bug causing this, but it should be fixed in the current release:
https://github.com/googlesamples/google-services/issues/141
I tried a workaround by calling AppInvite.AppInviteApi.getInvitation twice, as instructed in github error report. No success.
In onCreate I am checking that savedInstance is null and checking deep link only if it is.
I am checking deep link also in onNewIntent in order to handle it while the app is running, however this is not called when the problem occurs.
In my manifest, the intent-filter with the specific protocol and host are included only in the main activity. The protocol is used also in other filters in other activities, but I tried also using different protocol in those with no effect. Only the main activity uses AppInvite.AppInviteApi.getInvitation to get the intent. The problem occurs even if I remove other intent filters from all activities.
Any ideas what could be wrong or what I should still check?

You need to call getInvitation() both in your launcher activity, and in the activity which you declared to handle the dynamic link.
But in the activity which handles the dynamic link, you need to pass null instead of passing the activity as second parameter of getInvitation(),
like this AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, null, autoLaunchDeepLink).

Related

Firebase Dynamic Links does not work if the target app have run

I setup Firebase Dynamic Links in my project. At a glance everything works. But there is one exception. When I click the link my app starts and processes it. But if my app have already run and I click the link the app is appearing on the screen and it doesn't process the link because the intent in the FirebaseDynamicLinks listener is null.
I have only one Activity with singleTask launchMode and I subscribe for the FirebaseDynamicLinks in two places: onCreate() and onNewIntent().
I use the latest version of the library - 19.1.1
Can anybody explain me what I'm doing wrong?
It was my mistake.
In the onNewIntent(Intent) method I used Activity.getIntent() instead of incoming parameter.

React-Native Linking.addEventListener('url', this._handleOpenURL); not listening

In react-native, I am trying to log in the user using facebook/Google.
I am opening the URL in external browser, after entering credentials, It redirects back to app where, I have added an event
componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
}
In iOS, it is working fine.
But on Android, this never gets called.
I read somewhere that Linking works only with In app browser, I have also tried that, but Google does not allow that also. Attaching the image for that error please have a look also:
I have also gone through and alerted componentWillMount(), componentDidMount(), componentWillUpdate(), componentWillUnmount(), componentWillReceiveNewProps(), and _handleOpenURL() and I get nothing when I click the link and it "re-opens" the app from the background? What am I doing wrong?
Can any body help me please.
I need extreme help. I am stuck here.
Please guide me how to catch URL callback for android in React-Native.
Thanks.
In android we have to mention the launch mode as singleTask for the activity to restrict it to load only once.
Add this line for the activity that will be opened against this redirection:
android:launchMode="singleTask"
I had added this to application tag. which is wrong. It should be with activity tag.

Why do we get these "invalid" intents?

We have an app with an Activity that can be started in two ways:
From another Activity - always with some extra data filled in
From deep linking
As far as I can see this is always working just fine. We either get the Intent.ACTION_VIEW with a data URI, or we get some string extras.
However, we have a very few instances where action is Intent.ACTION_MAIN and there are no extra data.
The toString() of the Intent is as follows (class name changed):
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10400000 cmp=com.example.OurActivity }
Intent.getExtras() returns null, Intent.getDataString() returns null.
In which cases can this happen? Why is the category for the Activity Intent.CATEGORY_LAUNCHER? How can we get the data needed to show the user the right contents?
launchMode is not specified for the Activity. The only IntentFilter in AndroidManifest.xml is for the deep linking (and not the launcher category).
The issue happens on Android 4-6 on a wide range of devices.
Edit: Forgot to mention the flags:
As the print out suggests the flags for the Intent are FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_BROUGHT_TO_FRONT. I suppose that could be relevant here.
I believe, I nailed it:
There're launchers, like Nova Launcher which allows users to start with any of app's Activities, instead of the normal flow:
For example, you can add a shortcut on your desktop to start Gmail client with Account setup Activity.
And in this case, Activity is being started with empty Extras and technically it becomes a launcher's Activity.
Now that AndroidManifest.xml is manipulated by the build system, it often happens that libraries that you include also add things to the manifest, which I suspect may be happening here.
Although you state that there is only one IntentFilter in the manifest, have you actually checked the installed app to see what its manifest says (rather than relying on what you think you put in your source code)?
Various apps are available in the Play Store to show you the manifest of an installed app - including App Detective (which I wrote).

Referencing another package activity within a tab host

I've created an app that has been in the android marketplace for a few months now. I'm trying to create a complimentary app that will be used inside the first app. I need the second app to be optional, and not necessary for the first app to work properly. I'm hoping to call the main activity from the second app within a Tab Host tab on the first app.
My questions are: how do I run an activity from a secondary app with a different package? Is it possible to have the activity be in a tab host?
I'd be happy to post code, but my code seems to be nowhere close to what I'm trying to get. I don't think I can adjust the build path of the primary app, because the secondary app can't be required. Also, Since the app has been in the marketplace for a while, I can't use SharedUserIds.
Thanks for all help.
TJ
It is not possible to do it to run any arbitrary activity in your app.
I have done this before, with activity group, which has been already deprecated. And there are also limitations to use this approach:
Your app has the same UID with the target package.
Your app has system UID
If you met either condition list above, you can start the child activity and get its window root view, and add into your layout.

Android: security exception with launchMode="singleTask"

I have declared the launch mode of my activity to be singleTask. If I
launch my application, press the home button, go to an email client
(gmail in this case) & preview an attachment using my application, I
am experiencing a security exception on Android versions 2.3 & later,
which says that I do not have the permissions to access gmail
attachments. The exception does not occur on prior versions & if I do
not use singleTask as the launchMode.
The exception occurs on this line-
mContext.getContentResolver().openInputStream(intent.getData());
where mContext is the activity context.
Is this a known issue?
Any help will be really appreciated.
Thanks,
Akshay
I had posted this on Android-developers and got this response from Dianne Hackborn-
"Sorry, this is probably a bug in 2.3 with trying to grant a URI permission to an activity instance that is already running. I'll look in to this. In the mean-time, the only solution may be to not use singleTask for the activity being launched to a preview an attachment. This is actually the preferred thing to do, since your preview activity should be running as its own instance as part of the gmail task."
The problem might happen because the called intent's activity in the 2.3 implementation does not fit the launchMode:"standard" or launchMode:"singleTop" requirement stated in the android:launchMode description.
But it would be also useful to take a look at this issue: Behaviour of launchMode=“singleTask” not as described. It is scary, hopefully your problem isn't rooted there, and can be solved within the current versions.

Categories

Resources