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);
}
}
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 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>
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.
Launching an Android Application from the Browser
You cannot use MAIN
-- URLs in Android are only VIEW
ed from the browser or WebView
.
Also, none of your Intent
filters include the BROWSABLE
category, so they will never work with the browser.
It is not recommended to invent your own schemes. You can use a regular HTTP scheme, for some domain that you control. This sample project demonstrates this. In particular, you can follow the pattern shown by this filter:
<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="www.this-so-does-not-exist.com" android:scheme="http" />
</intent-filter>
replacing www.this-so-does-not-exist.com
with something you own, and perhaps adding in a path
to narrow the filter's scope. You can also see this technique used by the Barcode Scanner app from ZXing.
Unable to launch app from web browser
Typing a link in the browser doesn't start an intent: the browser just browses to that URL. The intent mechanism is only used when you follow (i.e. click) a link in the browser.
Related Topics
Android Sdk Content Loader Failing with Nullpointerexception
Xamarin Forms Android App Crashes Running Debug with VS Android Emulator
How Does One Implement Drag and Drop for Android Marker
Error Inflating Class Collapsingtoolbarlayout
Only One Log in Per User at the Time in Firebase for Android
Google Play Services Missing in Emulator (Android 4.4.2)
How to Get the Dreaded Write_Secure_Settings Permission for My Android App
Filling a Circle Gradually from Bottom to Top Android
Picasso Load Drawable Resources from Their Uri
How to Finish Activity When Starting Other Activity in Android
How to Get Information About Android Battery Usage by Application
Android - Use External Profile Image in Notification Bar Like Facebook
How to Detect a Dual-Core CPU on an Android Device from Code