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 : )

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks! Do you know if it's possible to open the link in a already opened tab (avoid opening a new tab)?
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 <key> <value>) with package name as value (com.android.chrome) - may be it works similar with the standard browser (com.android.browser).
I'm not sure how to use the EXTRA_APPLICATION_ID... should I get the app ID before and use in it?
Try to add -e Browser.EXTRA_APPLICATION_ID com.android.chrome; check for instance stackoverflow.com/questions/9901820/…
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 didnt 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 "google.com";` and got the same behavior
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.