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.
Related
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.
My question is when I want to share a tweet on from twitter app when I press the share button a pop up opens and displays all the apps that on which I can share my tweet. How does twitter app knows which apps to display?
This is similar to when an image is opened a pop up comes up and asks for the app we want to view the image in. How does any OS figures out which apps to display.
My guess is that something has to be done with the original application itself.
Attached is an image for reference
In the above screenshot Facebook, Twitter, G+ etc are using Intent Filters.
By defining intent filter you can achieve this. You can register your Android components via intent filters for certain events.If a component does not define one, it can only be called by explicit intents. The key for this registration is that your component registers for the correct action, mime-type and specifies the correct meta-data.
Eg.
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
Above code will register an Activity for the Intent which is triggered when someone wants to open a webpage.
Source: http://www.vogella.com/tutorials/AndroidIntent/article.html
I defined the following intent filter in my application in order to make it respond to url links.
<intent-filter>
<data android:scheme="http"/>
<data android:scheme="https"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
Now when I click a link in an external app (from example a link sent by sms) it opens my app in an embedded way in the current application. Meaning that if I go to background I see my app inside the sms application.
I want the link to make my application to be opened separately. This is the correct behaviour, and happens for example when choosing chrome/ android native browser as the app to open the link.
Is there a way to change that for my app as well?
You have to set the launchMode of your activity to singleTask or singleInstance. This will force the system to open a new task for your app instead of opening it in the same task as the sms-app or whatever.
It should look somehow like this:
<activity android:name="yourActivity"
android:launchMode="singleTask">
</activity>
For more information, see the documentation: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
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.
Hi
Is it possible to invoke an Android App from a Web Page that i am displaying on the phone browser to the user. I know that this is possible from an another Android App using Intents. But i am not sure if this is possible from a WebPage.
Thanks in advance.
Intent filters with the BROWSABLE category will let you launch an application using a URI scheme. Inside your <activity>, add:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="myprotocol" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
and set up the action and categories how you want, and change the scheme to something relevant to your application.
Then inside your webpage, you can link to your application with
test link
Simply define a intent filter for a particular URI within your Activity:
http://developer.android.com/guide/topics/manifest/data-element.html
That way, that activity will be called when a corresponding link is clicked. By using a custom scheme you'll make sure that your app is the only one responding.
It's the same way the android market responds to market links.