Deeplinking in Android app - android

I am trying to enable deeplinking in my app. Here is the code I am running in AndroidManifest to achieve it:
<activity
android:name=".ui.WalletActivity"
android:label="#string/title_activity_wallet">
<intent-filter android:label="#string/title_activity_link_wallet" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="wallet"
/>
</intent-filter>
</activity>
Is there anything else I need to do in order to make tapping on myapp://wallet to open WalletActivity of my app?

In my app, this works fine:
<activity
android:name=".ui.WalletActivity"
android:label="#string/title_activity_wallet">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<intent-filter>
<data android:scheme="myapp" android:host="wallet" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
I also have extra parameters (myapp://wallet?id=42), which I parse like this:
Intent intent = getIntent();
String providerUrl = intent.getData().toString();
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
sanitizer.setAllowUnregisteredParamaters(true);
sanitizer.parseUrl(providerUrl);
String id = sanitizer.getValue("id");
(You can read about UrlQuerySanitizer here)
To test, I'd suggest to send the myapp://wallet link to yourself via email, for example :-) (or adb, as mentioned in the comments)

To test and make sure that your intent is working, you can use adb command as suggested in the deep linking docs
To pass parameters in your uri, simply add them as a normal query parameter (i.e. example://gizmos/path?key=value, then retrieve them by parsing the intent data like this:
Uri uri = getIntent().getData();
String value = uri.getQueryParameter("key");
Make sure you check for nulls etc.

Related

URL scheme not working in android browser

I need my application opens when clicking on a link. for this I read that I must use a URL scheme. The link must have the form myapp://parameters.
I read every post on this subject, but when I send an email with "myapp://addUser/?id=22" and I open from chrome (on my phone), it is not clickable.
My manifest:
<activity
android:name="com.example.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="myapp" android:host="com.example"/>
</intent-filter>
</activity>
My class:
public class SplashActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String id = uri.getQueryParameter("id");
}
}
Content of the mail to test the code:
myapp://addUser/?id=22
Reference Links:
Make a link in the Android browser start up my app?
How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?
https://legacy.madewithmarmalade.com/devnet/forum/custom-url-scheme-primarily-android-3
UPDATE
I think the problem is the mail body, but I don't know how I can test this.
In your manifest
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="com.example"/>
</intent-filter>
you define android:host="com.example", so you should modify link URL :
myapp://addUser/?id=22 //error
myapp://com.example/?id=22 //correct
then it can work!!
I made a test here and in the manifest file I just removed the "android:host" parameter, leaving this:
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
and it opened an URL myapp://testing here that I put on a simple HTML file just for trying.

Redirect to Mobile app from facebook and twitter app

My Android app can share links via Twitter or Facebook.
If someone clicks on a link that was shared and they already have the app installed, how can I make the app launch directly?
Updated -
Simple Issue Fixed from here -
Make a link in the Android browser start up my app?
You need to add <Intent-filter> under <activity> tag in manifest.xml file like
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
When another application tries to share any of these things by constructing an intent and passing it to startActivity(), your application will be listed as an option in the intent chooser.
If the user selects your application, the corresponding activity (.ui.MyActivity in the example above) will be started. It is then up to you to handle the content appropriately within your code and UI.
And go to this for better understanding: http://developer.android.com/training/sharing/receive.html
Facebbok/twitter
facebook
After facebbok login OnComplete() is called. So, fire your intent in this method.
public void onComplete(Bundle values)
{
# fire desired intent
}
twitter
put this code into your manifest file with activity name and on which activity
want to redirect put the below line so link is created and you will redirect
<activity
android:name="com.example.mainactivity"
android:screenOrientation="portrait" >
<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="home"
android:scheme="oauth" />
</intent-filter>
</activity>
*********************************************************************
<h6>put this into your mainactivty</h6>
static final String TWITTER_CALLBACK_URL = "oauth://home";
static final String TWITTER_CALLBACK_URL = "oauth://home";

How to start app from Android browser, when I type in "myapp://" in address bar

I need the browser to start my app whenever I enter the "myapp://blah.com/a?b=1&c=2" in the browser. I have searched a lot on this topic, but non of the answers really helped me. Could you please help to understand what I'm missing?
<activity android:name=".MyAppMain"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="myapp" />
</intent-filter>
</activity>
After installation from Eclipse (Run As Android application) my app can work ok on its own, but when I type in "myapp://blah.com/a?b=1&c=2", the browser is simply googling for this string. Could you point out what else I'm missing? Do I need after installation to somehow register in the system that I want to handle "myapp://" urls?
I have done this using the
<activity android:name=".ReceiveInviteActivity">
<intent-filter >
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="appname"
android:host="project.example.com"
/>
</intent-filter>
</activity>
And activity
if (Intent.ACTION_VIEW.equals(action)) {
final List<String> segments = intent.getData().getPathSegments();
Log.d("LISTARRAY",segments.toString());
String idString = segments.get(0);
Log.d("LISTITEM",segments.get(0).getClass().toString());
String friendId = idString.substring((idString.indexOf("="))+1);
Log.d("friendId!",friendId);
I hope this will help you.
Check out this answer for why it isn't working: Android custom URI scheme incorrectly encoded when type in browser
Basically, the default Android browser only accepts certain URI schemes, so your custom one won't work when typed directly into the URL bar.

android custom url scheme..?

Im trying to create my own url scheme so my android app can get called via an URL but for now I dont have a success.
Im trying to have this url to work : cedemo://com.cedemo.scan?X=toto
Here is part of my manifest file :
<activity android:name=".Gallery1" android:label="#string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.GALLERY" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="cedemo" android:host="com.cedemo.scan" />
</intent-filter>
</activity>
Does anyone can help telling me what is wrong ?
Also, if someone find what is wrong, can someone tell me how I read the "X" variable from inside the android code from my app ?
Update:
Update: I did the modification of the action (as advised in one of the answers) and it's worked fine. The thing is that I still cannot get the url variable value. Here is the code I tried.
final Intent intent = getIntent();
final String myScheme=intent.getScheme();
final Bundle myBundle=intent.getExtras();
final boolean inContestKey;
if (myBundle != null) {
inContestKey=myBundle.containsKey("inContest");
}
final Uri myURI=intent.getData();
final String value;
if (myURI != null) {
value = myURI.getQueryParameter("inContest");
}
But I receiving null from all the functions… what else can i do?
May be I should explain better the context of my software:
My software is started
My software launch then the browser
the user click a link in the browser and the browser go to the url scheme, back to the software with a variable "X" (for example)
the software should read the variable "X"
But in my case : myScheme, myBundle, myURI are set to null.
Any ideas ?
Update:
I found the answer is that you have to be in the main activity to do that.
I think the problem is with the Action you defined.
There is a "android.intent.action.VIEW" which is what I think you want.
<activity android:name=".Gallery1" android:label="#string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<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="cedemo" android:host="com.cedemo.scan" />
</intent-filter>
</activity>
Try that and I bet will resolve correctly. I only made this assumption because you included the browsable category which is usually used by the Browser, which does not know of any of your custom actions. If you do want the GALLERY action as you have implied then just create 2 filters
<activity android:name=".Gallery1" android:label="#string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.GALLERY" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="cedemo" android:host="com.cedemo.scan" />
</intent-filter>
<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="cedemo" android:host="com.cedemo.scan" />
</intent-filter>
</activity>
So within the contents of your activity you can do something like:
// Value should be "toto" as in your example
String value = getData().getQueryParameter("X");
What finally fixed things for me was changing the order of the XML elements. Specifically, swapping the data and action rows so data is before action made it start working.
<intent-filter>
<data android:scheme="myappname" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And for completeness, my link in the html is "myappname://noop".
One more thing, i would like to throw light. Initially it was not working for me because i was using Main/Launcher tags before View/Default/Browsable/data.
Once i changed the order it started working fine.
i.e Initially not working code
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="myapp" />
</intent-filter>
correct code order
<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="myapp" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
and way to test for android is very simple.
Make any html file insert
test to launch myapp <br /><br />
just open this html file and click on test to .... :-)

Launch Activity From URL

I am trying to have my application launch when the user browses to a certain url. I have found a few examples and they all have the same things in the manifests but it's not working for me. I have put the intent-filter under an Activity as well as a Receiver.
Here is my manifest snippet:
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.urbandictionary.com" android:scheme="http"></data>
</intent-filter>
When under the Activity, I tried using onNewIntent and when it was under a Receiver, I tried using onReceiveIntent, both with a simple Log.i call to see if it fired or not. I am not having much luck.
I use this in my manifest.xml file:
<activity android:name=".SomeName">
<intent-filter>
<category android:name="android.intent.category.ALTERNATIVE" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="google.com" android:scheme="http" />
</intent-filter>
</activity>
This will start activity SomeName. I don't use www in the android:host part maybe that will make a difference.
When the activity starts you can get the data that's behind the .com using (for example):
Uri data = getIntent().getData();
if(data != null && data.getPathSegments().size() >= 2){
List<String> params = data.getPathSegments();
String somestuff = params.get(0);
}
Edit: If you wan't to be able to check the host from within the activity, use this method:
data.getHost();

Categories

Resources