0

My WebView does not launch with a normal URL

I have done everything I could, The browser is simply not launching... I have tried attaching webclient too, doesnt works. I have the internet permission in the manifest. Could anyOne help me here? :(
Its so simple and its not workin.

void somemethod()
   {
  WebView myWebView = new WebView(mycontext);
  myWebView.loadUrl("http://stackoverflow.com/questions/5066778/android-html-image-prob");
   }        
con_9
  • 2,491
  • 3
  • 23
  • 31

2 Answers2

0

This is not the code to launch a browser bro. This is the code to open url into the embedded webview inside the app.

To open the url in Android's default browser try this

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));

startActivity(myIntent);

To open a url into the embedded browser, embed a webview in a layout and then call the second line in your code.

Rahul Choudhary
  • 3,789
  • 2
  • 30
  • 30
  • ah sory for that, i tried the intent earlier, that was working, was wondering what was the pbm with webview.Webview.load doesnt lauches activity on its own? i need to create an activity for it?? – con_9 Sep 27 '11 at 08:30
  • Yes you are correct, WebView doesn't launch an activity on its own. It is like any other control button, imageview etc. It need to be embedded into an activity using layout (or programmatically) and then try to load the url into it. – Rahul Choudhary Sep 27 '11 at 08:31
  • 1
    Don't forget to accept the answer and upvote if you got the info you were looking for – Rahul Choudhary Sep 27 '11 at 08:38
0

If you really want to use WebView instead of Browser intent, there is two way. One way is to declare a webview in layout file, connect it to Activity class and set some attributes and load the url.

Other way is to declare the WebView dynamically. In that case you have to set necessary attributes, set layout parameters and you must add it to content view. Then load the url.

Here is a tutorial Hello, WebView

Walid Hossain
  • 2,724
  • 2
  • 28
  • 39