Launch custom android application from android browser

匿名 (未验证) 提交于 2019-12-03 01:31:01

问题:

Can anybody please guide me regarding how to launch my android application from the android browser?

回答1:

Use an with a element. For example, to handle all links to twitter.com, you'd put this inside your in your AndroidManifest.xml:

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:

Then, in your web app you can put links like:

 

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:

Uri data = getIntent().getData(); String scheme = data.getScheme(); // "http" String host = data.getHost(); // "twitter.com" List 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.



回答2:

Please see my comment here: Make a link in the Android browser start up my app?

We strongly discourage people from using their own schemes, unless they are defining a new world-wide internet scheme.



回答3:

All above answers didn't work for me with CHROME as of 28 Jan 2014

my App launched properly from http://example.com/someresource/ links from apps like hangouts, gmail etc but not from within chrome browser.

to solve this, so that it launches properly from CHROME you have to set intent filter like this

        

note the pathPrefix element

your app will now appear inside activity picker whenever user requests http://example.com/someresource/ pattern from chrome browser by clicking a link from google search results or any other website



回答4:

In my case I had to set two categories for the and then it worked:



回答5:

There should also be added to the intent filter to make the activity recognized properly from the link.



回答6:

For example, You have next things:

A link to open your app: http://example.com

The package name of your app: com.example.mypackage

Then you need to do next:

1) Add an intent filter to your Activity (Can be any activity you want. For more info check the documentation).

        

2) Create a HTML file to test the link or use this methods.

Open your Activity directly (just open your Activity, without a choosing dialog).   Open this link with browser or your programm (by choosing dialog). 

3) Use Mobile Chrome to test

4) That's it.

And its not necessary to publish app in market to test deep linking =)

Also, for more information, check documentation and useful presentation.



回答7:

The following link gives information on launching the app (if installed) directly from browser. Otherwise it directly opens up the app in play store so that user can seamlessly download.

https://developer.chrome.com/multidevice/android/intents



回答8:

Yeah, Chrome searches instead of looking for scheme. If you want to launch your App through URI scheme, use this cool utility App on the Play store. It saved my day :) https://play.google.com/store/apps/details?id=com.naosim.urlschemesender



回答9:

Please note if your icon is disappear from android launcher when you implement this feature, than you have to split intent-filter.

    


回答10:

Felix's approach to handling deep links is the typical approach to handling deep links. I would also suggest checking out this library to handle the routing and parsing of your deep links:

https://github.com/airbnb/DeepLinkDispatch

You can use annotations to register your Activity for a particular deep link URI, and it will extract out the parameters for you without having to do the usual rigmarole of getting the path segments, matching it, etc. You could simply annotate and activity like this:

@DeepLink("somePath/{someParameter1}/{someParameter2}") public class MainActivity extends Activity {    ... } 


回答11:

Hey I got the solution. I did not set the category as "Default". Also I was using the Main activity for the intent Data. Now i am using a different activity for the intent data. Thanks for the help. :)



回答12:

You need to add a pseudo-hostname to the CALLBACK_URL 'app://' doesn't make sense as a URL and cannot be parsed.



回答13:

example.php:

          


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!