HOW TO CREATE ANDROID APP FOR ANY WEBSITE - Andropro

Andropro

androidtutorialro

Breaking

Home Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Wednesday, June 13, 2018

HOW TO CREATE ANDROID APP FOR ANY WEBSITE

Create android app for blogger or website using android studio:

now a days all bloggers and website holders try to convert their websites and blog url into an beautiful customized apps.this post describes about how to create android app for bloggger,how to create android app for any website and how to create android app for wordpress.for this we need to study about android webview concept

WEBVIEW:


A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.


STEP1: ANDROIDMANIFEST.XML


Note that, in order for your Activity to access the Internet and load web pages in a WebView, you must add the INTERNET permissions to your Android Manifest file: 


so in your ANDROIDMANIFEST.XML
above the <application tag

PASTE THESE LINE:

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



STEP2: Activity_main.xml:

<WebView    android:id="@+id/wv"    android:layout_width="fill_parent"    android:layout_height="fill_parent">

</WebView>

In your activity_main.xml file,add an webview ,paste these code on activity_main.xml
(note : Replace webview with your mainactivity class name)


STEP 3:MainActivity.java:



to show url you need this line

WebView myWebView = (WebView) findViewById(R.id.webview);



to load url,use these on your main activity:

webView.loadUrl("http://.com");


JAVASCRIPT ENABLED REQUIRED FOR WEBVIEW:

by default java script is disabled in android studio....to make enable it you need to add these lines
to your code


webView.getSettings().setJavaScriptEnabled(true);

when the user click any external link it will go to other app, how to make downloads inside your android app:

webView.loadUrl("http://.com"); webView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { //download file using web browser Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); android studio webview backbutton fix:




during webview there causes many issues iike..andriod studio webview backbutton not working,webview navigation back not working,



while loading website url in android studio back button force stop app and exits and this can be 
prevented by following code:

 @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        else        {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }
}

on settin up all your MainActivity.java run the program and get the output

 android webview example:



activity_main.xml:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:id="@+id/wv"/>

</RelativeLayout>
MainActivity.java:
package astin.mypro.com.proj1;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;


public class MainActivity extends Activity {
    private WebView webView;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.wv);
        webView.getSettings().setJavaScriptEnabled(true);
        WebView webView = (WebView)findViewById(R.id.wv);

        webView.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(MainActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            }
        });




        webView.loadUrl("http://google.com");
        webView.setDownloadListener(new DownloadListener()
        {
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
            {
                //download file using web browser
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
            }
        });

    }
    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        else        {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }
}
Androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="astin.mypro.com.proj1">

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

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>




Post Bottom Ad

Responsive Ads Here

Pages