I've just setup App Links within my Android app, following the official Android guides online. I can click on a link and my app launches just fine.
However, I observe different behaviour depending on where the link was clicked from.
From the Gmail app, my app launches and all works well. Clicking the ||| icon at the bottom of the screen shows my app is running standalone.
From Slack, my app launches and works fine, but it appears to be a part of the Slack process. The back button doesn't function, and if I click on the ||| icon at the bottom of the screen then it shows that my app appears to be running inside Slack (there's only one window open).
From WhatsApp, the same happens as Slack.
This is from my AndroidManifest.xml:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="mydomain.com"
android:path="/" />
</intent-filter>
I suspect this is somehow related to Slack opening web links itself, but I don't know how to prevent this. This also doesn't explain the WhatsApp behaviour, as WhatsApp already seems to open web links in Chrome independently.
Any advice would be appreciated!
That's actually the default in Android- your app is launched as part of the caller's stack. You need to set the launch mode to singleTask in the manifest. Please note that this may sometimes cause onNewIntent to be called rather than a standard activity creation path, if the activity is already alive in the background.
Related
I have successfully set up an intent-filter in my Android app to open the app from the mobile browser based on one of many SO posts on this topic.
However, the problem is that the native app is opening WITHIN the browser, when I rather want it to open OUTSIDE of the browser in a separate app process.
By WITHIN, I mean that when I press the rightmost 'active apps' button to see what is running, I see that my current app is still the browser app, and there is no separate app opened called MyApp. It is as if the browser embeds my native app within itself, and so the browser is executing my app process.
And by OUTSIDE, I mean that I want to be able to see two active apps running after I press the link: (1) the browser app from which I launched (2) my MyApp app.
This is my intent-filter set up in AndroidManifest.xml:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="myapp" android:host="mypath" />
</intent-filter>
And I link to this from a web page opened in the browser using:
Open app
How can I force the app to open OUTSIDE of the browser? One note is that when the app launches I don't see an 'app chooser' which I've seen for other apps.
By WITHIN, I mean that when I press the rightmost 'active apps' button to see what is running, I see that my current app is still the browser app, and there is no separate app opened called MyApp.
Your activity was launched within the browser's task.
It is as if the browser embeds my native app within itself and itself is executing my app process.
That is not what is happening.
How can I force the app to open OUTSIDE of the browser?
If you mean that you want the activity to appear in a separate task... ideally, that would happen by default. I'm surprised that a browser would not have added FLAG_ACTIVITY_NEW_TASK when it started your activity.
That being said, android:launchMode="singleTask" on your <activity> element should give you the desired behavior.
In my app I have an intent filter set to match certain types of links if clicked in a web browser or other field. It currently looks like this:
<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.mydomain.com"
android:scheme="http" />
<data
android:host="mydomain.com"
android:scheme="http" />
<data
android:host="m.mydomain.com"
android:scheme="http" />
</intent-filter>
This works well. If you click a link say http://www.mydomain.com/article_name then the user gets the option of opening the article in the app and I can show the content uniquely. Here's the question - in the app I want to provide an option for the user to still break out and "Open in Browser". Yet if I do this and just try to fire off an intent to launch the browser, my app catches the link again and we go around in a circle.
How can I specifically force a link to be opened in the browser?
I believe you can use the answers provided in this thread to achieve your end. Basically, when you go to launch the "open in browser" intent, you can preview the activities that will be able to open it. From there, you can select one that isn't your app and set that as the package on the intent, which will cause the other app to open it.
At worst, you could force the creation of the chooser which would contain both your app and the other apps that can open your site, enabling the user to pick the browser.
This other question might also be useful, as its answers contain an implementation of a custom chooser which apparently allows you to filter the visible activities, so you could remove your app.
I don't know any way to bypass Android Intent Filter.
If user uses Android default Browser or Chrome, you should use the way in following link to open an Intent specifically.
https://developers.google.com/chrome/mobile/docs/intents
I'm recognizing special links to enable my users to launch my Android app when clicking on a link like "http://popp.us/ABCDE", for exemple from the Facebook messenger
For this, I implement in my Manifest file, inside my main activity tag :
<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:scheme="http" android:host="popp.us" />
</intent-filter>
It correctly works, but when I click the home button and relaunch the Facebook app, Facebook is still showing my own app. It seems to have launched my main activity inside Facebook app task.
Does someone know a way to force Facebook (or other apps) to launch my app in another task ?
This is the default behaviour since Honeycomb and I strongly encourage you to keep it.
That said, you can escape the task by setting the launchMode <activity> attribute to singleTask or singleInstance. See the documentation for more info. This will require you to use a separate Activity for that intent-filter, since it would mess up the normal use of the Activity in your app.
I created a basic Android app from the Eclipse wizard. I then added the following intent filter to AndroidManifest.xml, after the existing one. This makes it support a custom "sample://" URL scheme:
<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:scheme="sample" />
</intent-filter>
If I run Chrome or the default browser, and click a "sample://" link, it launches my app. However, if I look at the task switcher, my app isn't listed. Instead, Chrome is shown, with my app's screen shot.
Why is this? Can it be fixed? I'm running Android 4.2.2 on a Galaxy Nexus phone.
I notice that if I add android:launchMode="singleInstance" to the activity, it opens in a separate app. But the docs say this is "not recommended for general use". Why not?
The reason why you Activity appears in Recent Apps as Chrome is because it now belongs to the Chrome task, because it was launched from there.
As you noticed android:launchMode="singleInstance" solves your problem, however it is not recommended or discouraged because it would brake the user experience and navigation and how users expect your application to behave.
Fortunately, I think there's a way of specifying Intent flags in your HREF, try something like this:
<A HREF="intent:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.example.package/.MyActivity;end" />
in the previous example launchFlags=FLAG_ACTIVITY_NEW_TASK. This flag is generally used by activities that want to present a "launcher" style behavior: they give the user a list of separate things that can be done, which otherwise run completely independently of the activity launching them.
Edit / Update:
As an update to the below problem, I found the exact action which causes it to happen.
Download an apk from a url through the android browser
Install the app.
After install, the app gives you two choices: "Open" or "Done".
If you choose "Open", the quirky behavior described below starts.
If you choose "Done", then launch the app from the app tray, it works fine.
So it seems like this problem is caused by using the "Open" button the browser provides you after installing the APK.
I'm experiencing an error in the history stack of applications upon first install. I made a test app to demonstrate this.
The test app is simply two activities, A and B. Activity A launches B. That's all it does. Rest is wizard generated template code from eclipse.
When the user installs the app (via web url apk), and runs it for the first time, I get an out-of-order activity stack:
User starts the app, A is on top.
They make A launch B by clicking a button. B is on top of the stack.
User hits the home screen button.
User returns to the app, A is displayed, instead of B.
User hits the back key, B is shown!
User hits the back key again, A is shown!
User hits the back key again, home screen shown.
Now the stack is clean, and app behaves "normally" from now on!
Is any one else seeing this? This is almost exactly like this known bug, however my users are not installing from eclipse:
link.
I can provide the test app/source if anyone wants to try. This is the manifest, which does not have any special customizations made to it.
<activity android:name=".ActivityA"
android:label="ActivityA">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ActivityB"
android:label="ActivityB">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
As far as I know, this should definitely not be happening, and works fine after you clear the history stack the first time.
Thanks