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!
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.
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.
hi you can use the webview in android to load the web page here is the example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With