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?

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.
        
        
    }
}

Thanks very helpful thread, and for those who are new to Android System WebView App which offer web environment integration, see: What Is Android System WebView App? I hope this helps. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.