1

I have android application which contain html webpage with one single button. The html file is placed into the asset folder in android. I open html file into the webview. Now, i what want to open the another application which is install in android device by click on the html page button.

Can you please anyone help me how i will do that and also give me the some reference from where i will get some help?

Sk Maniruddin
  • 43
  • 1
  • 5
  • http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent or try this `Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address"); startActivity(launchIntent);` – Apurva Mar 16 '15 at 19:43
  • This is work for me [1]: http://stackoverflow.com/a/2958870/3758898 – Kishan Vaghela Mar 16 '15 at 19:48

2 Answers2

2

I think @Sk Maniruddin is asking how to open another app from a webpage. And the solution to that is using an intent, as the link.

  <a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>

for more information you can look at the doc: https://developer.chrome.com/multidevice/android/intents#example

kaho
  • 4,746
  • 1
  • 16
  • 24
0

Firstly set your onclik method of button in html like this.

<input type="submit" name="submit" id="submit_id" onclick="click.performClick();" />

enable javascript your webview

webView.getSettings().setJavaScriptEnabled(true);

after that you can detect this click by this code:

webView.addJavascriptInterface(new Object() {
            @JavascriptInterface
            public void performClick() {// detected click 
                Intent i = new Intent(FromActivity.This, DestinationActivity.class);
                    startActivity(i);

            }

        }, "click");
Cüneyt
  • 2,565
  • 25
  • 31
  • interesting. I used this method on my 2 projects and it was work. Are you sure to make evrything correctly? Did you notice the name that before ?.performClick(); must be same with the end of the addJavascriptInterface method's parameter? – Cüneyt Mar 16 '15 at 20:43
  • webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("file:///android_asset/index.html"); webview.addJavascriptInterface(new Object() { @JavascriptInterface public void performClick() {// detected click // Intent i = new Intent(FromActivity.This, DestinationActivity.class); // startActivity(i); Toast.makeText (MainActivity.this, "Hello", Toast.LENGTH_SHORT).show(); } }, "click"); I write the above code. – Sk Maniruddin Mar 16 '15 at 20:47
  • Did you set click method of button in html like this? onclick="click.performClick();" – Cüneyt Mar 16 '15 at 20:50
  • Yes. I use same method. – Sk Maniruddin Mar 16 '15 at 20:52
  • 03-17 02:23:16.901: I/chromium(16994): [INFO:CONSOLE(12)] "Uncaught TypeError: undefined is not a function", source: file:///android_asset/index.html (12) I got message like above. – Sk Maniruddin Mar 16 '15 at 20:53
  • Can you try webview.getSettings().setDomStorageEnabled(true); – Cüneyt Mar 16 '15 at 20:58
  • I throw in the towel :) I hope you will find the solution. Have a nice day. – Cüneyt Mar 16 '15 at 21:05