Android Question SetApplicationAttribute(android:usesCleartextTraffic, "true") not working anymore

cbanks

Active Member
Licensed User
Longtime User
I have the following code
B4X:
SetApplicationAttribute(android:usesCleartextTraffic, "true")
in my manifest and it has worked for a long time. It no longer works. I am unable to stream mp3's from non-ssl sites now. Has something changed?
 

cbanks

Active Member
Licensed User
Longtime User
The following code does not work either:

B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
If your app is for personal use set
B4X:
targetSdkVersion="26"
in the Manifest.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.

It does not work with targetsdk set to 30 or more i guess
 
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
If you have to publish on the market then you have to stick to Google Policy and I think that there are no workaround for this.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I am unable to stream mp3's from non-ssl sites now. Has something changed?
I have had sdk set to 31 for quite a while and it has worked fine. I have not changed the sdk version and it just won't work now.


The test app below is using targetSdkVersion="33" and has no issues with the non-https site http://serenewonderfulsoothinglight.neverssl.com/online/ . Are you sure everything is working properly with the site you are trying to access?

Update: Hardware: Pixel 7, OS: Android 14
 

Attachments

  • ClearTextTest.zip
    14.1 KB · Views: 34
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
I've attached an updated app of the ClearTextTest with the problem I'm talking about. If you uncomment the https mp3 then it plays it fine. If you uncomment the http mp3 line then it doesn't play and throws an error (MEDIA_ERROR_UNKNOWN, -1015). One change that I made was switching from a paid web host to a free web host.
 

Attachments

  • ClearTextTestMP3.zip
    10.4 KB · Views: 33
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I've attached an updated app
The issue is not with the App but with the requirements of MediaPlayerStream. According to the B4X documentation:
According to the native documentation the online resource must support progressive download.

From some quick "Googling", it looks like a server has to support ranges (Accept-Ranges) and the "HTTP" server that hosts the MP3 file in question does not support ranges.

I've attached an updated example that includes a way to test if a site supports Accept-Ranges

Link:
 

Attachments

  • ClearTextTestMP3v4.zip
    463.8 KB · Views: 41
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the site does have an accept-ranges header, but the particular mp3 is short and appears to have been obtained with a simple get. there doesn't seem to be much "streaming" involved. does op have another (preferably much longer) example?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
the site does have an accept-ranges header, but the particular mp3 is short and appears to have been obtained with a simple get.
So it looks like it is a server-side configuration issue as it pertains to small files on the HTTP server (if it otherwise supports accept-ranges). If you download the mp3's of both sites, they are the same size. The HTTP server does not support accept-ranges for that particular file and the HTTPS one does. My conclusion was that the HTTP server itself does not support accept-ranges, but it could be that it does not support accept-ranges for small(ish) file sizes (or maybe, for some reason, just this file). In the end, not having an accept-ranges in the returned header is why the file from the HTTP server fails to play with MediaPlayerStream.
 
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
Thanks to all for your help! I'm assuming at this point that a free web host will not suffice for what I want to do in my app. I've tried quite a few free web hosts and none of them seem to allow insecure mp3 streaming. I assume because of the lack of accept-ranges in the returned header. I was trying to get-away with not paying for a web host or ssl but that doesn't seem possible.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I'm assuming at this point that a free web host will not suffice for what I want to do in my app. I've tried quite a few free web hosts and noce of them seem to allow insecure mp3 streaming. I assumed because of the lack of accep-ranges in the returned header.
It depends. It could just be a configuration issue on the server that can either be changed by the user or maybe through a support ticket.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
a free web host will not suffice for what I want to do in my app
It could just be a configuration issue
Try this (not guaranteed to do anything):
1) In the folder where the mp3 file is located, create a file named
.htaccess
2) Add the following content(s) to the file:
<IfModule mod_headers.c>
Header set Accept-Ranges 'bytes'
</IfModule>

This may not work, since the header must also include a correct content-length (the size of the file). Or the server used is not Apache-based. Or .htaccess is not allowed. And many other failure points...
 
Upvote 0
Top