Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I embed a website in my app

Tags:

android

I am currently creating an app, only now I have got to a point where I would like to be able to embed a website into the actual app itself. The thing is I would like to be able to view the website without leaving the app, so it is embedded into the app somehow. I am realising that this might not be as easy as it sounds as it almost needs a browser, though I don't really need to do any browsing as such, I only need to load the site and then display it. Is this even possible (isn't anything possible?)

Thanks!

like image 658
Taylrl Avatar asked Jun 03 '12 09:06

Taylrl


People also ask

How do you embed a website?

Go to the social post or webpage you'd like to embed. Generate the embed code using the post's options. If applicable, customize the embed post, such as the height and width of the element. Highlight the embed code, then copy it to your clipboard.


2 Answers

You will need a WebView for it.

But the point here is you want to embed the website in you application.

Following Snippet will help you out.

public class HelloWebViewActivity extends Activity {
    private WebView mWebView = null;
    private EditText mInputUrl = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mInputUrl = (EditText)findViewById(R.id.input_url);
    Button button = (Button)findViewById(R.id.button);
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new HelloWebViewClient());
    button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              String url = mInputUrl.getText().toString();
              mWebView.loadUrl(url);
            }
        });


}

private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
    }
}
}

Remember to include android.permission.internet permission in you manifest. Also always make sure you specify url as http://www.google.com or https://www.google.com if you don't prefix http or https then webview will not display web page.

like image 108
Vipul Avatar answered Sep 18 '22 18:09

Vipul


hi you can use the webview in android to load the web page here is the example

like image 41
Munish Kapoor Avatar answered Sep 21 '22 18:09

Munish Kapoor