I have a strange issue. My app is using http to connect to a server. It works fine in many devices. However, in Xiaomi devices which has Android 9, it gives me this error:
Caused by java.io.IOException: Cleartext HTTP traffic to internet.vodafone.com.eg not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:142)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:469)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:418)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:549)
at com.google.firebase.perf.network.zzd.getResponseCode(zzd.java:81)
at com.google.firebase.perf.network.zzb.getResponseCode(zzb.java:14)
at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:96)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
In the AndroidManifest.xml I have this:
<application
...
android:networkSecurityConfig="#xml/network_security_config"
...
</application>
My network_security_config.xml file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">thebondnews.com</domain>
</domain-config>
</network-security-config>
Also, I have all the permission to connect to the internet. It works fine in Many devices with android 9 Like Samsung galaxy s9/s9+ and Samsung galaxy s8/s8+ and many others.
The error message was copied from Firebase Crashlatics. What is strange is that my server domain is thebondnews.com but in the log, it says internet.vodafone.com.eg or sometimes notification.etisalat.com.eg and 10.10.10.1. It is like there is kinda redirection in their devices.
Can anyone help me how to solve it? or what shall I do?
Update 1:
Could it be that I am only allowing my domain in network_security_config.xml
and because of the redirection caused by their providers the connection fails?
As Md. Asaduzzaman said in the comments.
The internet package of that user has finished and the operator tries to redirect him to the internet package page.
So it was not an issue with the app. However, some users have a limited internet package with limited access to things like Facebook, WhatsApp, Instagram..etc.
Thus, when my app tries to connect to the server, it is being redirected by the internet provider to block the traffic.
Related
EDIT:
I have an error that crash my application, java.lang.SecurityException: uid xxxxx cannot explicitly add accounts of type: package.name , I know there are other similar posts here, but I cannot find a solution.
I think the following happens, when a user wants to login to the application, there are cases where the application crashes. when does it crash? when calling the addAccountExplicitly method. I checked the Android permissions and the authentication file which are the most common causes, and tried to log in with both of my apps at the same time to try to replicate the crash, but was unsuccessful.
The problem occurs in the first seconds of use, when I am trying to add an account, the line where it crash is the following
if (accountManager.addAccountExplicitly (account, null, null))
where accountManager and account are
val account = account
val accountManager = context.getSystemService (Context.ACCOUNT_SERVICE) as AccountManager
I have no idea why this happens, and why it does it only to some users.
I wanted to know if having two different signature packages could lead to the problem, for example I have the same application with package name package.name1 and package.name2, package.name1 is different from package.name2 just for GUI. Can someone help me please? It is one of my first posts on stackoverflow, sorry if I made a mistake.
It is not a recurring bug but it appears every week at least once
EDIT:
I have two flavors for each app.
Authenticator 1:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="package.name1"
android:icon="#mipmap/ic_launcher"
android:smallIcon="#mipmap/ic_launcher"
android:label="App1" />
Authenticator 2:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="package.name2"
android:icon="#mipmap/ic_launcher"
android:smallIcon="#mipmap/ic_launcher"
android:label="App2" />
Permissions
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
EDIT: Well, I found something interesting, the application has 11 crashes in 90 days, and all cases were on Android 11, was there any change in Android 11 that may affect the add AccountExplicit method?
i have searched for this problem but cant resolve that problem
i have internet in android 8 but in android 9 dont have any connection
usesCleartextTraffic=true >> not resolved
NetworkSecurityConfig >> not resolved
my url have https and ssl certificate but i dont have any internet connection only in android 9
this is security config below
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">ketabenarenji.ir</domain>
</domain-config>
</network-security-config>
I don't think we understood each other, go check my answer in this post WebView shows net::ERR_CLEARTEXT_NOT_PERMITTED on HTTPS url it'll help you on how to configure your files.
EDIT: I just went on your website and it tells me it's not secure even though you have https:// you might wanna fix your certificate, once it's fix you can remove all the useClearTextTraffic and the file network_security_config
Well, I have built an app to store values on a remote database. It works!! I didn't use an emulator for testing instead I used my own phone. Now the problem is that on my phone, it works perfectly...no issues but when I installed it on another phone, the app doesn't connect to the internet.
I have included internet permission in android manifest.xml.
I have tried these but didn't work:
Building apk and installing in the new phone.
Compiling directly to the new phone.
Sending the apk from old phone to new phone via shareit.
Creating a signed apk and installing.
Checked via wifi and mobile data (NOTE: BOTH WIFI AND MOBILE DATA WORKS IN OLD PHONE).
Checked android compatibility: supports up to android 10.
*I added error messages for try...catch blocks in form of toasts for the user to know what's the issue. and the catch exception for no internet returns connection problem. I'm getting that error message.
As I researched, I got to know that internet permission is categorized as normal permission which is not prompted to the user upon installation.
I built a second dummy app: Same issue with it... compiled directly to new phone but didn't work...it works in old phone...
Old phone: Samsung J7 Prime with Android 8.1
New Phone: Samsung J7 Pro with Android 9
Any idea or suggestion will be gladly helpful... Thank you!
in android 9 and above you have to set network Security Config
first of all in res package create xml package and in xml package create new xml resource file with network_security_config name
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
then in manifest in
android:networkSecurityConfig="#xml/network_security_config"
<uses-permission android:name="android.permission.INTERNET" />
Use debug APK instead of signed APK
please add permission on Manifest to give a permission of permission.INTERNET
I have android application which connect to "hosturl" over the web. This application can connect to hosturl in the initial steps, but after i try to test it for some time(say 20 or more requests), I get above exception and I can not no longer connect to above url.
If i restart my android handset, then application can again connect to the "hosturl" but again I get the exception after I have tried to connect to hosturl few number of times
Could anybody help me here If you have encounter such a behavior with an android application before.
You probably don't have the INTERNET permission. Try adding this to your AndroidManifest.xml file, right before </manifest>:
<uses-permission android:name="android.permission.INTERNET" />
I met this and I just closed my AVD and start it again and it worked...
Check your Internet connection.
Check Wifi.
Check Server.
I'm using google api java client for connecting to Google Docs in Android app.
Once in a while i get following exception:
UnknownHostException: www.google.com
Code:
transport = AndroidHttp.newCompatibleTransport();
ClientLogin authenticator = new ClientLogin();
authenticator.authTokenType = "writely";
authenticator.username = username.getText().toString();
authenticator.password = password.getText().toString();
authenticator.transport = transport;
authenticator.authenticate().getAuthorizationHeaderValue();
Device reset clears exception but is it necessary.
I suspected for DNS caching and tried following but didnt work. Im not behind a proxy as far I know.
Security.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.negative.ttl","0");
System.setProperty("net.eth0.dns1","8.8.8.8");
System.setProperty("net.dns1","8.8.8.8");
Last time it occurred was this morning when one network connection "died", cell auto got second one, tried to do ClientLogin but failed with exception.
Just to make it clear, Im talking about DEVICE (htc desire hd), not emulator.
Thanks in advance.
add this line to your AndroidManifest.xml file, just after the <manifest> tag and before the <application> tag:
<uses-permission android:name="android.permission.INTERNET" />
I run into this daily. I think it is a bug in the emulator. After reset of emulator it works again and it never happened on a real device.
Edit: most definitely a bug in the emulator. See this thread. There are also several posts on StackOverflow regarding those emulator connection issues.