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.
Related
I am working in app. There need to create a deep link. User can able to share particular item and user can open direct page from click link. I follow enter link description here
<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="www.jobzminer.com"
android:pathPrefix="/appplay" />
<data android:scheme="jobzminer"
android:host="appplay" />
</intent-filter>
but when i put link into browser then its not working.
As mentioned in the comments, to update your url to: https://www.jobzminer.com/appplay. Also clear your browser as a default app.
To pass parameters, you could use query parameters. Change your url like this: https://www.jobzminer.com/appplay?param1=hello¶m2=world
Then in your activity. Do this:
Intent intent = getIntent();
Uri data = intent.getData();
String param1 = data.getQueryParameter("param1");
String param2 = data.getQueryParameter("param2");
You can also see my answer here.
Deeplinking can be well achieved by Branch SDK. They have amazing docs to integrate branch sdk and get going. Refer this link https://dev.branch.io/getting-started/sdk-integration-guide/guide/android/
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¬ify_entity_id=7221752¬ification_type=22¬ify_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¬ify_entity_id=7221752¬ification_type=22¬ify_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.
I want to create an activity that opens only when links with a specific URL are clicked.
For example: i want to open http://mysite.xyz/test?param=val#myid=12345 with my app (activity), but http://mysite.xyz/test?other=stuff i want to be opened with default browser.
I'm trying to create an intent filter 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:scheme="http"
android:host="mysite.xyz"
android:pathPattern="????" />
...
</intent-filter>
My problem is that android:pathPattern or pathPrefix do not (seam to) verify the query string (any text after the ? or the last /).
Is there a solution for this filtering ?
I haven't tried it myself, but I think you can handle the links based on the URL path, up to the "?" or the last "/". Then, in your activity, check the last part (after ? or last /) and if it doesn't match your criteria, you can redirect the user back to the default browser.
You can use android:ssp, android:sspPrefix and android:sspPattern attributes.
But it works only in 4.4 and higher.
I'm trying to pass data to my activity, but unfortunately I'm still unsuccessful. What I am trying to accomplish is to select a file in the file browser, share it and pass the data to my activity.
Inside my manifest I added an intent filter:
<activity android:name=".MyActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
Inside my Java file i'm trying to get the data:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myactivity);
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
// process the data
} else {
// no data received
}
}
When I select a file from My Files and share it, my app is visible in the list, when i click it it launches my activity, but intent.getData(); always returns null.
Am i missing something? Thanks.
you can get the data from the example given below:
Use an with a element. For example, to handle all links to twitter.com, you'd put this inside your in your AndroidManifest.xml:
<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.
Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:
<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, in your web app you can put links like:
<a href="my.special.scheme://other/parameters/here">
And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.
Edit: To answer your question, 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:
strong textUri 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 ienter code heren the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.
Launch custom android application from android browser
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.