-1

I have made an android app which uses webView. Everything was fine until I tried my app on Android P. On Android "P" the app is directly showing the error page that the app can't use Internet connection even though it is ON.

Android Manifest File:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxxxx.xxxxx">

    <!-- android:roundIcon="@mipmap/ic_launcher_round" -->

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.xxxxx.xxxxx.xxxxxx.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

Gradle File:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.xxx.xxx.xxx"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 3
        versionName "3.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0'
}

On Getting error in Android P, directly this section is being accessed:

public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                // You can redirect to your own page instead getting the default error page

                super.onReceivedError(view, errorCode, description, failingUrl);
                String path = Uri.parse("file:///android_asset/error.html").toString();
                webView.loadUrl("about:blank");
                view.loadUrl(path);
            }
Alok Raj
  • 328
  • 3
  • 9
  • 1. Not enough information about error. Please edit your question to include what error is being generated. 2) I would try `file:///android_asset/error.html` as a plain String without Uri.parse(). – Morrison Chang Jan 20 '19 at 05:49
  • Thanks, I removed the .html file to see the exact error. – Alok Raj Jan 20 '19 at 07:17
  • Possible duplicate of [WebView showing ERR\_CLEARTEXT\_NOT\_PERMITTED although site is HTTPS](https://stackoverflow.com/questions/52707918/webview-showing-err-cleartext-not-permitted-although-site-is-https) – Radesh Apr 10 '19 at 14:24

2 Answers2

0

I'm not an Android expert, but you have told Gradle that you don't want to support Android older than version 19 in the gradle file.

Change that to match the minimum version you really want to support and rebuild your app. You will probably get build errors pointing out the APIs that you shouldn't be using, and other portability problems. Correct them.

Reference:

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

I found the error, net:ERR_CLEARTEXT_NOT_PERMITTED The solution was WebView showing ERR_CLEARTEXT_NOT_PERMITTED although site is HTTPS

Alok Raj
  • 328
  • 3
  • 9