6

I'm writing a script to run on android's terminal and I need it to open the browser and a URL. I managed to open the browser but didn't find a way to put the URL on it.

am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity;

Appreciate any help : )

Adami
  • 335
  • 5
  • 15

1 Answers1

10

Just use Intent.ACTION_VIEW (i.e. android.intent.action.VIEW), e.g.:

am start -a android.intent.action.VIEW -d http://www.xing.de

This way the XING site is started. If you have more than one browser installed, you can of course add the component name of the browser you want to start, e.g.:

am start -a android.intent.action.VIEW 
         -n com.android.browser/.BrowserActivity -d http://www.xing.de

Cheers!

Trinimon
  • 13,839
  • 9
  • 44
  • 60
  • Thanks! Do you know if it's possible to open the link in a already opened tab (avoid opening a new tab)? – Adami May 10 '13 at 19:36
  • That depends on the browser you use; in my case the new site was loaded into the opened tab by default. For Chrome you could add an extra called `Browser.EXTRA_APPLICATION_ID` (use `-e `) with package name as value (`com.android.chrome`) - may be it works similar with the standard browser (`com.android.browser`). – Trinimon May 10 '13 at 20:03
  • I'm not sure how to use the EXTRA_APPLICATION_ID... should I get the app ID before and use in it? – Adami May 10 '13 at 20:19
  • Try to add `-e Browser.EXTRA_APPLICATION_ID com.android.chrome`; check for instance http://stackoverflow.com/questions/9901820/browser-extra-application-id-not-working-in-ics – Trinimon May 10 '13 at 21:18
  • I tried `am start -a android.intent.action.VIEW -n com.android.browser/.BrowserActivity -e Browser.EXTRA_APPLICATION_ID com.android.browser -d "http://www.google.com";` it didn`t work, keeps opening a new tab... also tried `am start -a android.intent.action.VIEW -e Browser.EXTRA_APPLICATION_ID com.android.browser -n com.android.browser/.BrowserActivity -d "http://www.google.com";` and got the same behavior – Adami May 10 '13 at 21:52
  • Also tried with chrome, both ways and only with -a -e -d values but no success =/ – Adami May 10 '13 at 21:59
  • You know what? I think `Browser.EXTRA_APPLICATION_ID` is just a constant from the Browser class (check http://developer.android.com/reference/android/provider/Browser.html). Calling an intent, I'm pretty sure it works with this extra. Try `-e com....application_id com.and... ` – Trinimon May 11 '13 at 07:59
  • Thanks, it's opening webpages in the same tab now. I just need to find how to run a javascript after the page is opened... if I execute `am start -a android.intent.action.VIEW -n com.android.browser/.Main -e com.android.browser.application_id com.android.browser -d "javascript:alert('hello')";` then a new tab will be opened – Adami May 11 '13 at 16:03