Make a Link in the Android Browser Start Up My App

Make a link in the Android browser start up my app?

I think you'll want to look at the <intent-filter> element of your Manifest file. Specifically, take a look at the documentation for the <data> sub-element.

Basically, what you'll need to do is define your own scheme. Something along the lines of:

<intent-filter>
<data android:scheme="anton" />
<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>

Then you should be able to launch your app with links that begin with the anton: URI scheme.

Open an Android app via a URL in the browser

There are several things in play here.

First, as Blackbelt noted, Android is case-sensitive, as are most programming languages and development environments. You would need to change this to be the proper case, following the documentation for those actions and categories:

<intent-filter>
<data android:scheme="myapp" android:host="hello"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Second, not all Web browsers handle schemes like myapp:// the same. I am not aware of any law on the books in any jurisdiction forcing developers to honor them. There are three basic patterns that you will encounter:

  • Some browsers may handle them just fine

  • Some browsers will handle them when such URLs are used in links on a page, but not if the URL is typed in the address bar

  • Some browsers will not attempt to find an activity to handle them and just fail all the time

Google's preferred alternative is for you to use an http or https scheme, with a host and path that you control. Some browsers will always open the Web page, but others will check, see that there is an activity that advertises support for that URL, and give the user a choice of how to handle it. The "M" version of Android will provide further hooks ("App Links") that can bypass the chooser. Plus, other apps (e.g., text messaging clients, email clients) will typically make http links clickable, allowing users the choice of opening up your app, whereas few apps will know that myapp://hello is meaningful in the same way.

How can I open a URL in Android's web browser from my application?

Try this:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

That works fine for me.

As for the missing "http://" I'd just do something like this:

if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;

I would also probably pre-populate your EditText that the user is typing a URL in with "http://".

How to open Android app, after a click on website link?

Are you doing this?

Go to Tools > App Links Assistant.

  • Follow the guidelines by creating URL mapping by clicking on the "+" button.
  • Select the activity and add the logic to handle intent.

  • Third, and the most important step is to have access to the website you are mentioning. You need to add Digital Asset Links
    file by generating it and adding it to the mentioned location.

  • You can test the app links now by visiting the website from your browser. You are ready to go.

NOTE:

  • By following the procedure you can make sure the app supports deep linking, however it is completely upto the user who can control to enable or disable to open the website and redirect it directly to your app.

  • Make sure you have your app defaults URLs set to open the app with your app. Visit,

    App Info > Open by default > Open supported links > Open in this app.

Documentation:

  • https://developer.android.com/training/app-links

  • https://developer.android.com/studio/write/app-link-indexing.html

Launch android application from a browser link

It took me 6 hours to figure out the problem. Somehow setting the exported to false caused all the problem: android:exported="false". When I set it to true, it worked like a charm.

Funny because I put it there in the first place to avoid the Exported activity does not require permission warning. Setting it back to true, brought back the warning, but it is working now.

Solution is below. Hope it will help others save time.

<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:exported="true">
<intent-filter>
<data android:scheme="allplayer" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>


Related Topics



Leave a reply



Submit