Saturday, December 26, 2020

How to create android app using webview for existing website URL easy steps

 Today you will create your app any difficulty following below easy steps

1) First install java JDK in your local system 

sudo apt update

sudo apt install default-jdk

java -version

2) Download android studio 

        https://developer.android.com/studio

  Then open your terminal command and run the stuido.sh  file in bin folder using below command

           ~/Downloads/android-studio-ide-201.6953283-linux/android-studio/bin$ ./studio.sh

3) Create a new project and select empty activity

4) Then paste below code into this file and save.

    /home/bikas/AndroidStudioProjects/xxxx/app/src/main/AndroidManifest.xml

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

5)  Paste below code into 

     /home/bikas/AndroidStudioProjects/xxxx/app/src/main/AndroidManifest.xml

and update your website url in 

 mywebView.loadUrl("https://funnytrap.com/");

---------------------------------------------------------

package com.example.funnytrap;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView mywebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView=(WebView) findViewById(R.id.webview);
mywebView.setWebViewClient(new WebViewClient());
mywebView.loadUrl("https://funnytrap.com/");
WebSettings webSettings=mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
public class mywebClient extends WebViewClient{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view,url,favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view,String url){
view.loadUrl(url);
return true;
}
}
@Override
public void onBackPressed(){
if(mywebView.canGoBack()) {
mywebView.goBack();
}
else{
super.onBackPressed();
}
}
}

------------------------------------------

6) Paste below code in /home/bikas/AndroidStudioProjects/FunnyTrap/app/src/main/res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
7) Paste below code 
/home/bikas/AndroidStudioProjects/FunnyTrap/app/src/main/res/values/themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.FunnyTrap" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

8) Update your icon image of app
  i) in android studio left sile app folder
  ii) select drawable folder and right click then select go to new and select finally image asset
   and choose your icon from your local machine.
9) Finally build your app 
  i)Go to build menu in top select the sub menu "Generate Signed bundle/apk.."
  ii) select apk
  iii) Enter your app name and any password which you want 
  iv) then press OK to build your project to .apk file
  v) select release then create your app
Finally go to your release app folder and find your .apk file
/home/bikas/AndroidStudioProjects/FunnyTrap/app


Hope it will help you and let me know if question on this.