invoking an intent using html link - android

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

Related

Deeplink on click opens intent chooser in android

I have implemented deeplinking in one for my activities. But when the link is clicked, an Intent chooser opens asking whether to open from the app or from the browser. How to open from app directly?
Also, when the app is not installed, it does not take to playstore. It opens in the browser.
Below is my code in the manifest :
<activity android:name=".activities.VideoNewsDetailActivity"
android:theme="#style/AppThemeActivity"
android:configChanges="orientation|screenSize"
>
<!-- Add this new section to your Activity -->
<intent-filter android:label="#string/videoNewsDetail">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Handle urls starting with "http://www.example.com/products" -->
<data android:scheme="http"
android:host="ddnews.apprikart.in"
android:pathPrefix="/videos" />
<!-- Handle local urls starting with "example://products" -->
<data android:scheme="ddnews.apprikart"
android:host="videos" />
</intent-filter>
</activity>
This is how intent filter work. If more than 1 app can handle your intent, it will show an intent chooser. It's up to the user whether they want to open the link in your app or browser.
Your server should handle the playstore redirection part. For example your deeplink url is http://www.example.com/page/1. Now when the app is not installed the server can check if the url is called from a browser, then it should redirect the browser to the playstore's app url.
#Eric B. is right.
Even if you want only your app can open that link then you need to use custom scheme in intent-filter, like:
android:scheme="ddnews"
And need to build link like, ddnews://domain.com/dir/page.html

Intent Filter passing data through url and reading into activity

In my app, I need to open one page from out side app, through link which is in email.
In my app when some one will create post from our website then we are sending email with url.
When user will click on url/link then it will open respective page in the app.
I need to pass some id and other value to the activity when it launch.
Example:
we are sending following link through email when some one create post on website.
https://www.example.com/lt-url-redirector.php?user_guid=4074395&notify_entity_id=7221752&notification_type=22&notify_id=56933b6219b05172&baseurl=https://www.example.com/groups/calendar/aggregation/mlt
After clicking on above link it goes to mobile browser where "Open in App" button is there.
After taping on this button it gives:
window.location.href = 'abcdef:/?user_guid=4074395&notify_entity_id=7221752&notification_type=22&notify_id=56933b6219b05172&baseurl=https://www.example.com/groups/calendar/aggregation/mlt';
I want to pass notify_entity_id, notification_type, notify_id etc to the activity when it launch.
Android Manifest code :
<intent-filter>
<data android:scheme="abcdef" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Those are query parameters, and there are a variety of methods on Uri for retrieving those values, such as getQueryParameters(). To get the Uri, call getIntent().getData() from some likely spot, such as onCreate() of your activity.

How to OAuth 2.0 login using Chrome custom tabs (Fitbit API)

Fitbit API doesn't support webview anymore.
So, I studied chrome custom tabs and applied in my app.
But after login, when I pressed this pink button(allow button), nothing happened.(Image below)
How can I receive access token and store it in app?
Please help me.
Thanks.
When authorizing agains the Fitbit API, you need to provide a redirect_uri, which is where the user will be taken after logging in. You need to provide a uri that will take the user back to your application.
To achieve that, create an intent filter and add a data tag with a custom scheme, such as myapplication://logincallback to the Activity you want to handle the login.
The intent filter will look something like this:
<intent-filter . . . >
<data android:scheme="myapplication" android:host="logincallback" />
. . .
</intent-filter>
Now, set the redirect_uri as mypplication://logincallback to the authorization step of the flow, and when the user clicks the pink button, it should open the Activity you added the intent filter.
You will be able to retrieve the parameters inside your activity by calling getData on the Intent.
<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="logincallback"
android:pathPattern=".*"
android:scheme="myapp" />
</intent-filter>
Suppose you have redirect_uri myapp://logincallback, then add above code in your activity in Manifest xml file and it will work.

Custom URI in Android devices and iOS devices

I had a problem with Custom URI.
Custom URI : scheme:\music\album\tamil\albumID
When I mail this as text it appears as link in iOS devices as link but not in Android devices.
When user select/click the Cutom URI it should navigate to my app and have to show the appropriate content.
This custom URI is passed from one website's button click. In iOS device its react as link not in Android devices.
The web end passing the Custom URI as below
href="scheme://music/tamil/album/albumID"
As a Android developer what should I do to resolve this ?.
Or from web end how to pass the Custom URI as link?.
I think your mail provider/client is responsible for this behaviour. Gmail for example removes custom URIs and replaces href links from <a> tags. This may be for security reasons, not sure why. I suggest you to use "http" as scheme. Then Android will prompt you to open with browser or your app. Add intent filter as below example.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
You may also add a android:host, and android:path or android:pathPrefix if needed.
Another option is to use a redirect 302. An example for php is below. The drawback is this will open the browser at first.
<a href="openmyapp.php?cat=music&albumID=9128">
<?php
header("Location: scheme://". $_SERVER['QUERY_STRING']);
exit;
?>

Launch android app when a link is tapped on SMS

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.

Categories

Resources