Android - Convert Website to Android App and Solve Error Text Permitted

News Ever


Android - Convert Website to Android App and Solve Error Text Permitted


Are you looking for a method to turning a website into an Android app? If so, let me assure you that it is quite simple, and you will need to insert WebView with it.

Simply follow the lesson step by step, and your application will be ready to use. Webview is an element that may be used for this; add it to your XML (layout) file and implement it with several lines of Java code.

Note: please be sure the website should be responsive(mobile friendly).

Step 1: Create a new project in Android Studio (File -> New -> Project -> Select Empty Activty -> Name project WebViewApp -> Finish )

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="com.cambotutorial.webviewapp.MainActivity">
 <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Step 3: We will implement on Java class. Let's open MainActivity.java ( src -> package -> MainActivity.java )

package com.cambotutorial.webviewapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity

{
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://ebay.com");
    }
}

setWebViewClient(new WebViewClient()); we add this to prevent the website launch the browser after we click on some links which are run outside the app.

setJavaScriptEnabled(true); use for enabling Javascript to execute, some websites required to render UI.

Step 4: In android to be able to access the internet we have to add permission in AndroidManifest.xml. Open app -> manifests -> AndroidManifest.xml

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

Step 5: In the browser whenever we go to a website and click other links that will add in history so now we will implement on back press button to go to the previous history website unless there is no more history we will exit the application. Let's open MainActivity.java

@Override
public void onBackPressed()
{
    if(webView.canGoBack())
    {
      webView.goBack();
    }
    else
    {
      super.onBackPressed();
    }
}

In this step, we can try to run the application and we can see it works fine.

Anyway, we might get an error if we place the link which starts with http:// not https:// the error would show net::ERR_CLEARTEXT_NOT_PERMITTED .

Step 6: In AndroidManifest.xml. Open app -> manifests -> AndroidManifest.xml
we insert an attribute value in the application element android:usesCleartextTraffic="true"

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.cambotutorial.webviewapp">
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:usesCleartextTraffic="true"
        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>

After adding a line above the app can access any protocol and not produce an error. You can watch the video below to find out more clearly

Post a Comment

  • Latest Biss Key + Frequency
    • NHL Service - 10762 V 28800 (7E) - Biss : 12 24 01 D3 11 4B 97 F3 
    • Varzish Sport HD - Yahsat 1A Satellite - Biss Key: 12 34 00 46 EB CD 00 78
    • Bein Sport - Eutelsat 16A Satellite - Biss Key: 12 24 01 D3 11 4B 97 F3
    • Discovery HD UK / Sky One HD - 12188 H 29500 8/9 - Astra 28E
    • Fox Sports Eredivisie 1 HD - 12073 H 30000 - Eutelsat 9E
      • BBC Earth - 11064 V 27500 - Eutelsat 25E
      • BBC Red Button HD 2/3/4/5/6 - 12421 H 27500 2/3 - Astra 28E
      • beIN SPORTS HD NEWS 12604 H 27500 2/3 Nilesat 7W
      Cookie Consent
      We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
      Oops!
      It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
      AdBlock Detected!
      We have detected that you are using adblocking plugin in your browser.
      The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
      Site is Blocked
      Sorry! This site is not available in your country.