Android Question [solved]Content Chooser fails on newer Xiaomi devices (here: Mi 10t Pro)

KMatle

Expert
Licensed User
Longtime User
Just got a new phone with Android 11 (Xiaomi 10 T Pro)

Using this example: https://www.b4x.com/android/forum/t...example-select-image-at-phone.109022/#content just fails.

Image can be selected but CC_Result is False.

No logs and my other apps which receive shared selected images by the user (directly via Gallery, select & share to my app not using CC) work with no problems. Nothing in the logs (even unfiltered), no exception. On my other Xiaomi phone (9 T Pro) with Android 10 it works.

Did I miss a thing?
 

peacemaker

Expert
Licensed User
Longtime User
I have tested with emulator of Android 11, and with my Samsung M21 with Android 11.
The example works OK as is.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
ContentChooser works with all Android versions.

Complete code:
B4X:
Private Sub Button1_Click
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("image/*", "choose image")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Log(Success)
    If Success Then
        ImageView1.SetBitmap(xui.LoadBitmap(Dir, FileName))
    End If
End Sub

It can happen, usually in older devices, where the process is killed while the app is in the background.

Please try the attached project.
 

Attachments

  • Project.zip
    13.8 KB · Views: 136
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Same result. Success = False.

Logs:

B4X:
** Activity (main) Pause event (activity is not paused). **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
false
** Activity (main) Resume **
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Erel's example works on my Pixel 4A with Android 11.

I have a Xiaomi Mi Max 3 and a Redmi Note 9 Pro with Android 10 and they seem to be quite aggressive at killing processes. B4A Bridge doesn't live long in the background. I think this is characteristic of Xiaomi devices so Erel's guess might be correct.

If you are fed up with the intrusive adds everywhere see the attached. I wouldn't now buy another Xiaomi , Redmi or Pocophone device again.
 

Attachments

  • Xiaomi Disable Ads.txt
    2 KB · Views: 151
Upvote 0

agraham

Expert
Licensed User
Longtime User
When chooser activity is started - the example app is killed on the background - do you mean this ?
That's not what I said. I merely observed that they seem to be quite aggressive at killing processes, Whether that is happening here or not I have no idea.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
@KMatle,
If to google - there are lots of articles about Android 11 ROM bringing lots of troubles to Xiaomi 10 T Pro
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

KMatle

Expert
Licensed User
Longtime User
In the developer options you have to enable MUI optimisations 🤦‍♂️ On my 9t Pro is was enabled by default, on my 10t Pro not. Found this hint somewhere in the www.

Even other apps like K9 (mail apps) had issues with selecting files (e.g. attachements) which is solved with this solution, too
 
Last edited:
Upvote 0
Top