Launch Android Application from a Browser Link

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://".

Launch Android App from WEB browser

Guess I got my own answer after some more research:

It only works in Google Chrome but does the job in my case:

Links should look like:

<a href="intent://invoice/#Intent;scheme=company;package=company.printapp;S.doctype=FRA;S.docno=FRA1234;S.browser_fallback_url=http%3A%2F%2Fgoogle.com;end">PRINT INVOICE</a>

In the AndroidManifest.xml the important part is:

...

package="company.printapp"
...

<!-- Allow web apps to launch My App -->
<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="company" android:host="invoice" android:path="/"/>
</intent-filter>

And finally this is how I get the parameters I pass in the Intent link (doctype and docno):

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle parametros = getIntent().getExtras();
if (parametros != null){
String Doctype = parametros.getString("doctype");
String DocNo = parametros.getString("docno");
TextView textView = (TextView) findViewById(R.id.DocNo);
textView.setText(DocNo);
BluetoothPrint(Doctype,DocNo);
}
}

Launching an App from a URL

Thanks for your replies. In the end I had to change my intent to the below and it had the desired result. When I click the URL specified in my intent the application chooser pops up allowing me to load the link in my app.

Just as info for anyone struggling as I did, you do not need to read data from incoming intents for the application chooser to launch, all you need is the below in your AndroidManifest file.

<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="http" />
<data android:scheme="https" />
<data android:host=".website.com" />
</intent-filter>

Thanks All.

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.



Related Topics



Leave a reply



Submit