0

Hey,

I'm trying to open a web page inside my newest android app. (I'm following this guide...)

http://developer.android.com/reference/android/webkit/WebView.html

My goal with the app is to open up the web page every time it gets opened, but the web pages need to open within the activity.

With the code below, it does open the web page, but inside the browser app, how can I open the web page inside my own app?

What specific changes do I need to make on my .java activity file, and my .xml layout file?

// part of .java activity file

WebView webview = new WebView(this);
setContentView(webview);

webview.loadUrl("http://www.google.com/");

I haven't modified the .xml file, but should I?

2
Contributors
1
Reply
5
Views
6 Years
Discussion Span
Last Post by mustafaneguib
0

the code that you have given here works.

following is my complete activity

public class WebViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        
        /*Uri uri = Uri.parse("http://www.google.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);*/
        
        WebView webview = new WebView(this);
        setContentView(webview);
        
     // Simplest usage: note that an exception will NOT be thrown
        // if there is an error loading this page (see below).
       // webview.loadUrl("http://slashdot.org/");

        // OR, you can also load from an HTML string:
        String summary = "<html><body>You scored <b>192</b> points.</body></html>";
        webview.loadData(summary, "text/html", null);
        // ... although note that there are restrictions on what this HTML can do.
        // See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.
        
        
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.