Thursday, February 18, 2016

Create webviev android app

Convert any website with android app


In Main_Activity.xml add this code :

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>



To load a web page in the WebView, use loadUrl(). For example:

In MainActivity.java add this line code :

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");



Enabling JavaScript



WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);





Handling Page Navigation

To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient(). For example:



myWebView.setWebViewClient(new WebViewClient());



Navigating web page history

For example, here's how your Activity can use the device Back button to navigate backward:


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the Back button and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
        myWebView.goBack();
        return true;
    }
    // If it wasn't the Back key or there's no web page history, bubble up to the default
    // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}





Before this will work, however, your application must have access to the Internet. To get Internet access, request the INTERNET permission in your manifest file. For example:

In AndroidManifest.xml  add this line of code

<manifest ... >
    <uses-permission android:name="android.permission.INTERNET" />
    ...
</manifest>


IT IS IMPORTANT TO CORRECTLY IMPORT SETTING

No comments:

Post a Comment

Namecheap.com