I met Cleartext HTTP traffic to www.soundhelix.com not permitted
error when i tried to stream mp3 files with the Exoplayer library.
2019-10-06 18:22:28.363 8724-9511/com.codechacha.exoplayer E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:282)
.....
Caused by: java.io.IOException: Cleartext HTTP traffic to www.soundhelix.com not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:124)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
....
The cause of the problem is that Android doesn't allow HTTP access by default. Accessing HTTPS is no problem, but if the site doesn't support HTTPS, or if you need to access HTTPS, you should handle this.
According to Opt out of cleartext traffic in Android Developer, Starting with Android 9 (API level 28), cleartext support is disabled by default.
So, you have to configure about cleartext HTTP
to get access to HTTP sites with API level 28 or above.
Allow all connections to HTTP URLs
You can allow all connections to HTTP URLs if you set the usesCleartextTraffic
property to true in AndroidManifest.xml
<application
android:label="@string/app_name"
...
android:usesCleartextTraffic="true">
Allow connections to specific sites.
If you want to allow connections to specific sites. then make a /res/xml/network_security_config.xml
file and add some sites.
if you add a domain-config like below, you can allow connections to secure.example.com
.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">secure.example.com</domain>
</domain-config>
</network-security-config>
Also, you have to let the system know where the config file is. Add following code to your AndroidManifest.xml.
<application
android:label="@string/app_name"
...
android:networkSecurityConfig="@xml/network_security_config"
References
Related Posts
- How to download and build Android 13, AOSP
- Notification permission request, pop up notification in Android 13
- Resolve `Access blocked: ComponentInfo` error on Android 13
- Fix error "android gradle plugin requires java 11 to run. you are currently using java 1.8."
- Android - Vibration, Vibrator, VibrationEffect example
- How to get phone number in Android
- How to create Bugreports and Logcat with ADB in Android
- Clear application user data with ADB in Android
- How to disable/enable apps with ADB in Android
- How to find PID of a package with adb in Android
- How to grant/revoke permissions with adb in Android
- How to install an apk(app) with adb in Android
- How to kill a process/package from ADB in Android
- How to transfer files using adb push/pull command in Android
- How to capture the screen from adb in Android
- How to uninstall/install system apps from adb in Android
- How to change Settings values from adb in Android
- How to Factory reset with ADB in Android
- How to get logcat from ADB command in Android
- How to capture Heap Dump from app with ADB in Android
- How to force stop an app with adb in Android
- How to start/stop a service from adb in Android
- How to send/broadcast an intent from adb command in Android
- How to start an activity from adb in Android
- How to generate input from adb in Android
- How to check SQLite DB table in Android Studio
- How to get memory info and thread list from adb in Android
- Android - Uri, Scheme and SSP(Scheme Specific Part)
- How to parse a xml file with XmlResourceParser in Android
- Android - Signing an apk with Platfom key
- How to fix "Cleartext HTTP ... not permitted" for Android development
- How to fix "kvm permission denied" for Android Emulator
- Using ADB over Wifi for Android development