Launch android app when a link is tapped on SMS - android

I don't know if many people have tried this but I am trying a build an app that requires user to tap on a link on the sms he/she receives and this will launch the android app. Is it possible to do in android? If yes, how can I do this? I know this can be done in IOS. Any suggestions or help will be appreciated. Thank You.

In you Manifest, under an Activity that you want to handle incoming data from a link clicked in the messaging app, define something like this:
<activity android:name=".SomeActivityName" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="com.your_package.something" />
</intent-filter>
</activity>
The android:scheme="" here is what will ensure that the Activity will react to any data with this in it:
<data android:scheme="com.your_package.something" />
In the SomeActivityName (Name used as an illustration. Naturally, you will use your own :-)), you can run a check like this:
Uri data = getIntent().getData();
String strData = data.toString();
if (strScreenName.equals("com.your_package.something://")) {
// THIS IS OPTIONAL IN CASE YOU NEED TO VERIFY. THE ACTUAL USAGE IN MY APP IS BELOW THIS BLOCK
}
My app's similar usage:
Uri data = getIntent().getData();
strScreenName = data.toString()
.replaceAll("com.some_thing.profile://", "")
.replaceAll("#", "");
I use this to handle clicks on twitter #username links within my app. I need to strip out the com.some_thing.profile:// and the # to get the username for further processing. The Manifest code, is the exact same (with just the name and scheme changed).

Add an intent-filter to your app that listens for links that follow the format you want your app to be launched on.
However, this will be a global listener, and any link that fits the format even outside the SMS app will trigger your app. So if the user taps a similar link in the web browser, your app will attempt to respond to it.
Additionally, if there is another app besides yours that can handle this link, Android will create a chooser that allows the user to pick whichever app they want to use. There is nothing you can do about this, except suggest that the user make your app the default handler for such links.

<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"
<data android:scheme="https" android:host="${hostName}" android:pathPattern="/.*" />
</intent-filter>
Previous answers are OK but don't forget to specify the pattern.
See more details here.
Also define your hostname inside Gradle file like:
android {
defaultConfig {
manifestPlaceholders = [hostName:"subdomain.example.com"]
}
}
More info about manifestPlaceholders here.

Related

Firebase Deep-link opening play store even when the app is installed

I'm developing an android app.
Upon clicking a button, a deep-link is generated and shared with friends.
The problem is that upon clicking that shared deep-link, play store is getting opened even when the app is installed.
I followed this documentation.
Here's the intent-filter:
<!-- [START link_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:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
</intent-filter>
<!-- [END link_intent_filter] -->
Here's how I'm creating the url (manually):
Uri BASE_URI = Uri.parse("https://domainname.com/");
packageName = getBaseContext().getPackageName();
APP_URI = BASE_URI.buildUpon().path(requestID.getText().toString().trim())
.appendQueryParameter("query1", query1.getText().toString())
.appendQueryParameter("query2", query2.getText().toString())
.appendQueryParameter("query3", query3.getText().toString()).build();
try {
String encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8");
deepLink = Uri.parse("https://myappcode.app.goo.gl/?link="+encodedUri+"&apn="+holder.packageName+"&amv="+16+"&ad="+0);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Here's the received deep-link/url: http://domainname.com/-KcldzAeJHrPS5tnfxTk?query1=query1&query2=query2&query3=query3
What could be wrong here?
There are at least three things that could possibly be wrong:
The way you are opening the url:
I saw similar problem when writing the url to browser window on Android device. When adding the link to an email and clicking it, the app was opened. You write "click" so perhaps this is not the problem.
Your url and your app/manifest do not match:
You have not added proper intent handler for the protocol or the host to correct place in your manifest or your url does not match with what you have added. Or apn given in the url does not match your apps package name. Based on the question in the current state the host does not match.
You are not sharing the deeplink url, but just an ordinary url:
If you expect the shared url to open preinstalled app, your friends will need to click (on an email or similar) the complete deeplink url, which then either directs the link to play store (if app is not installed) or opens the app (if correctly implemented). Normal url is just opened in the browser. Based on the current state of the question, this could be the case.
If fixing the above does not work:
Try adding specific Android link to your url, something like this:
https://<myappcode>.app.goo.gl/?link=http://domainname.com&apn=com.doman.app&amv=16&ad=0&al=myscheme://any-string-you-choose
after which your intent filter should be something like this:
<!-- [START link_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:host="any-string-you-choose" android:scheme="myscheme"/>
</intent-filter>
<!-- [END link_intent_filter] -->
I prefer this way since it is a bit more flexible compared to using only link. Naturally the package name and other things need to be correct also when using this method. Android link is url to be opened only in android app, a bit poorly documented, check it from here (the example). Also my reply to another question gives some examples on how to use it.
(edit 19.3.2018) It seems that Firebase does not fully support 'al=' anymore. The code works, but it is missing from the documentation and Firebase console generated urls.

Android, when opening shared location, my map not visible in system choises

for example, in whatsapp someone send own location and when we click to message system opens choise dialog with map apps that can open location like google map, yandex map and others. I want that my map app also be there. Other words, I want that system recognize my app as map app and when user click to location in whatsapp or other apps my app appear in system choise dialog. How can I configure my app to open location? I searched and in forums and android documentation they recommend to use implicit intent for it. But they dont show how to configure app that shows in system choises. I heard about mime-types but in documentation there are no mime-type for location.
You need to add an intent-filter to your activity that allows it to respond to map URLs. In your Androidmanifest.xml:
<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="maps.google.com" />
<data android:scheme="https" android:host="maps.google.com" />
<data android:scheme="geo"/>
</intent-filter>
To retrieve the URI:
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
Uri data = intent.getData(); // Here you will receive the URI
// ...
}
Implicit Intent's are more of like Your app to other apps sort of thing and you're aiming for the reverse version (Other apps to your app). What you are looking for is Intent Filter. As per the docs:
To allow other apps to start your activity, you need to add an <intent-filter> element in your manifest file for the corresponding <activity> element.
Cheers! :)

invoking an intent using html link

I am trying to implement a new feature for my android application.
scenario :
when some event occurs, the camera sends an email to my (Gmail) account.
on opening the mail, it will have a link (html).
when user clicks on that link, it should launch my application Home activity.
I need to understand :
how to create that html link.
how can i make the link to launch my application Home activity.
kindly help me to understand what all things i need to do in my application.
I used "Blackbelt's" user comment and i was able to get the intent html link working.
But my problem is : i want to use a custom scheme "mobile" instead of "http"
I am using Gmail to use the link. But when i send using custom scheme. Gmail doesnt recogonise as hyperlink. So i cannot click on the link.
Please help me how to use a custom scheme. with gmail
you need to register an intent-filter for your Activity on the AndroidManifest.xml file, defining a custom url. . E.g.
<activity android:name="path.to.YourActivity" >
<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="https"
android:host="it.is.my.app" />
</intent-filter>
</activity>
So if you press on a link like https://it.is.my.app, you should be prompted with the android intent chooser, with your app

In Android, how to open an app in browser

Suppose I have a web page, and I load that page in a browser on an android device. What I expect is, when I click a button in the web page, an app can be opened.
Is there any way to do that? Thanks a lot.
you can achieve this using <intent-filter> with a <data>.
For example, to handle all links to sample.com, you'd put this inside your in your AndroidManifest.xml:
<intent-filter>
<data android:scheme="http" android:host="sample.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
this one was well explained by Felix in his answer here
hopes this helps you...
If you have the option to customize the app in question, you could add an Intent Filter for a specific URI scheme which is unique to your app. Then in the click event for the button of the web page, use this URI scheme to launch your app.
For example, Google Play uses a market:// scheme to open the Google Play app from links.
using IntentFilters it is possible..
Chack out the following code:-
<intent-filter>
<data android:scheme="**myapp**" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <--Not positive if this one is needed
...
</intent-filter>
now you can start your app like myapp://
you can use getIntent().getData() which returns a Uri object. You can then use Uri.* methods to extract the data you need. For example, let's say the user clicked on a link to http://twitter.com/status/1234:
Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"
You can do the above anywhere in your Activity, but you're probably going to want to do it in onCreate(). You can also use params.size() to get the number of path segments in the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.

What makes Google Maps/Youtube able to display the 'Complete this action with' menu?

And if possible, how can I get this behavior for 'my' app?
For example, when a user navigates to the URL 'example.com/*' (any page starting with example.com), I'd want it so the 'complete this action with' menu shows up listing all of the browsers and this particular app?
I've done some reading of the Intent documentation, but it seems like you can only create them for phone data, not web URLs.
Edit: anyone? I've looked into this some more, but haven't had any luck. I'd like to set a bounty, but I don't have that option yet. If it isn't possible, I guess I'll just make a way to paste in a URL.
It's pretty simple, actually! What you want is an intent filter with the BROWSABLE category set, and a <data> tag set up to match your URL.
Inside your <activity>, add:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="www.example.com" />
<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 data tag values to something relevant to your application. This will allow your link (in this case, http://www.example.com/) to be launched in your application by the browser.
Take a look at http://developer.android.com/guide/topics/intents/intents-filters.html#ires
It's really well described how to use intent filters and why, especially in the section Common cases (http://developer.android.com/guide/topics/intents/intents-filters.html#ccases).

Categories

Resources