In this example, I will show you how to open an external (default) browser from an application. I start with the simplest example. I created a new project and glued a button labeled “Gugiel!”. When you press the button, you should start the browser running


We are going to the activity code now. Line 18 is a reference to the button. I have to do it to appeal to him. Lines 19-27 is a click of a button at the right button Action is happening in lines 22-24 and basically only limited to them. The address I want to open will have to be passed as a Uri object, so I create it based on . This may be the site of your company, for example, or a link to a search engine that has parameters passed to it. To start the browser we have to create a URI address and call a new intent – which is in lines 23,24.


At the press of a button, I started the default browser running the indicated address.


We’ll make our application a little bit easier now. The user enters the address of the page to be called. I add to the EditText view and change the text of the button.


It has to do a little modification in the code. We are interested in lines 23 and 24. In line 23 I added a handle to the editing window. On line 24, the url is based on the http: // start point (because everyone probably forgets it and will not do that) and the text entered in the edit box. The remainder of the program remains unchanged.


One more curiosity, albeit more as a “bajeru”. If we find in the file the layout of the element responsible for our EditText and add android: inputType = “textUri”, then when you click on the text input box will pop up the keyboard with special buttons for entering the URL eg “www” 🙂


These input types are much more types, including entering email addresses, numbers etc.