954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Opening a Web Page In An Android App

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?

Joe34
Junior Poster in Training
92 posts since Nov 2010
Reputation Points: 10
Solved Threads: 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.
        
        
    }
}
mustafaneguib
Junior Poster
104 posts since Apr 2008
Reputation Points: 14
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: