Launch Custom Android Application from Android Browser

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);
}
}

create a custom android browser that open a url that other apps request

Your question isn't really clear, but if you're talking about handling intents sent from other apps to open the URL in webview this tutorial on android developers training explains it pretty well.

Launching custom Android application from Android browser / Chrome

You need to set it up 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:host="example.com"
android:pathPrefix="/someresource/"
android:scheme="http" />
<data
android:host="www.example.com"
android:pathPrefix="/someresource/"
android:scheme="http" />
</intent-filter>

Notice that in your case, you would need to use android:pathPrefix instead of android:path.

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.

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>

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.



Related Topics



Leave a reply



Submit