Android Pie webview and network issue

sapan
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");
Tags

Post a Comment

1Comments
  1. Shadow Fight 2 Mod APK is a fun action fighting game where you control a shadow warrior. The game has smooth controls, so your punches and kicks feel natural. The mod version gives you unlimited coins and gems, which means you can upgrade weapons without waiting. You also get strong armor and powerful blades from the start. The fights are exciting and full of movement. Every stage becomes more challenging, so the game never feels boring. The animations are stylish and look very clean. You can learn different fighting styles and use many weapons. The gameplay feels fast, and the boss fights are intense. If you enjoy action games, this download Shadow Fight makes the experience even better and more enjoyable.

    ReplyDelete
Post a Comment

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !