HTTP Links Not Opening in Android WebView in Android Studio Java? - android

When I open a URL that Starts with "https://" in android WebView it works properly and Play a Video in video player from same type of URL ("https://") video also plays well.
But whenever I tries to open non secure ("http://") URL WebView and Video Player both don't work. If you have any solution of this question then please answer ?

Starting with Android 9 (API level 28), cleartext support is disabled by default.
You need to set Manifest and res/xml/network_security_config.xml properly. Below example is for http://test.com:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="#xml/network_security_config"
... >
...
</application>
</manifest>
res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="false" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">test.com</domain>
</domain-config>
</network-security-config>

Related

networkSecurityConfig not working for http connection

I'm testing http connection with apache server on ec2 and my android app.
Connection works fine on emulator(API 24) but it won't work on my Samsung Galaxy S10(API 29).
Tried everything related to configuring network_security_config.xml but nothing worked.
In my build.gradle minSdkVersion is 16 and targetSdkversino is 29. Below are my trials. (Let's assume i'm trying to connect to IP address of 1.2.3.4)
1) Adding custom network_security_config.xml
in res/xml/network_security_config.xml,
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">
1.2.3.4
</domain>
</domain-config>
</network-security-config>
in my manifest,
<application
android:networkSecurityConfig="#xml/network_security_config"
2) Setting usesClearTextTraffic as true
in my manifest,
<application
android:usesCleartextTraffic="true"
3) Applying both 1) and 2)
in my manifest,
<application
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
4) Setting tools:targetApi with 3)
in my manifest,
<application
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
tools:targetApi="29"
5) using base-config instead of domain-config
in res/xml/network_security_config.xml,
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
I have no idea what's wrong here.

Failed call api http in android

i am using API localhost in android but can not call it from android. I have change localhost became IP but can not call it too. I have been using another API and it is success. I think it is because of http connection.
In the end i am using this reference. I also get some answer from this.
You need to define a res/xml/network_security_config.xml and permit HTTP for that host:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">server.com</domain>
</domain-config>
</network-security-config>
That network_security_config.xml also needs to be referenced in the Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
...>
<application
android:networkSecurityConfig="#xml/network_security_config"
...>
...
</application>
</manifest>

Socket.io stopped working after updating android sdk to 28

I am building an Android application which is using socket.io.
I have updated it to use the sdk 28. It works fine on browser but not in the real device or emulator.
The AndroidManifest.xml file contains the following:
<application android:hardwareAccelerated="true" android:icon="#mipmap/icon"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:supportsRtl="true"
android:usesCleartextTraffic="true">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">mysocketdomain.com</domain>
</domain-config>
</network-security-config>
There is no way to downgrade the sdk since Google is not accepting apps using sdk below 28.
What the heck is goin on? I've read some issues related to this and no solution has worked at all...
Also, it is not a problem with the socket not any other code, since when I load the app via browser it connects immediately to the socket and I've tested socket sending messages, the browser is receiving. The real device, no.
It was a mistake of mine. Instead of false, it should be true, as following. The website should also be a domain and not an IP, making these changes, the socket in the device is working again.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">mysocketdomain.com</domain>
</domain-config>
</network-security-config>

How to fix cleartext traffic not permitted issue in Xiomi Redmi 3S with Android 6.0.1

When i am using URL with http then it shows an error "CLEARTEXT communication to (domain name) not permitted by network security policy" . I have tried cleartextTrafficPermitted = true in manifest.xml file but it is not compatible with payment gateway i use, which need cleartextTrafficPermitted = false. As it is API level 23 so, networkSecurityConfig = "#xml/network_security_config" doesn't work in it. I am using Retrofit as networking Library.
It is device specific issue Xiomi Redmi 3S, MIUI Global 10.2, Android version 6.0.1.
Any suggestion about this issue.
Finally i got solution by medium post , Code i used :
Step 1: create file : res/xml/network_security_config.xml
Add code in this file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">Your URL(ex: 127.0.0.1)</domain>
</domain-config>
</network-security-config>
Step 2: Add line in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:networkSecurityConfig="#xml/network_security_config"
...>
...
</application>
</manifest>

net::ERR CLEARTEXT_NOT_PERMITTED page is shown in my mobile web app for android 9.0 using phonegap

I am creating my web app using phonegap and it works fine but I come to know that it is not working in android 9 pie, it shows web page not found with the below message
net::ERR CLEARTEXT_NOT_PERMITTED
I tried to rectify it by adding the below code in my network-security-config.xml file
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
And also added the below lines in AndroidManifest.xml
<manifest... >
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true">
</application>
</manifest>
But I do not get it right. Can anyone help me with the solution ? Thanks in advance.
This simple code works for me:
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
And in AndroidManifest file:
android:networkSecurityConfig="#xml/network_security_config">

Categories

Resources