Android sending email from code

Android Pie webview and network issue

WebView issue in androidPie and above

If you are working with webView app in android pie. there are few issue I was facing.

    1. unable to load http url
    1. getting net::ERR_CLEARTEXT_NOT_PERMITTED
solution

Due to network security webview is not able to load http url. To Solve this.
in res -> xml folder create network_security_config.xml file, in this file add your domain

<?xml version="1.0" encoding="utf-8"?>  
<network-security-config>  
    <domain-config cleartextTrafficPermitted="true">  
        <domain includeSubdomains="true">androidlearner.com</domain>  
    </domain-config>  
</network-security-config>

Now open AndroidManifest.xml and add

android:usesCleartextTraffic="true"  
android:networkSecurityConfig="@xml/network_security_config"

in application tag. Like:

<?xml version="1.0" encoding="utf-8"?>  
<manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  package="skd.app.webapp">  
    <uses-permission android:name="android.permission.INTERNET" />  
  
    <application  
  android:allowBackup="true"  
  android:icon="@mipmap/ic_launcher"  
  android:label="@string/app_name"  
  android:usesCleartextTraffic="true"  
  android:networkSecurityConfig="@xml/network_security_config"  
  android:roundIcon="@mipmap/ic_launcher_round"  
  android:supportsRtl="true"  
  android:theme="@style/AppTheme">  
        <activity android:name=".MainActivity"  
  android:usesCleartextTraffic="true">  
            <intent-filter>  
                <action android:name="android.intent.action.MAIN" />  
  
                <category android:name="android.intent.category.LAUNCHER" />  
            </intent-filter>  
        </activity>  
    </application>  
  
</manifest>
    1. Web view is opening in default browser when called loadUrl
solution

set myWebView.setWebViewClient(new WebViewClient());
example :

//find the webView  
WebView myWebView = (WebView) findViewById(R.id.myweb);  
  
//Load url in webview  
 
myWebView.setWebViewClient(new WebViewClient());  
myWebView.getSettings().setJavaScriptEnabled(true);  
myWebView.getSettings().setSupportMultipleWindows(false);  
myWebView.loadUrl("http://www.androidlearner.com");

Comments