Android Question ContentChooser only shows Internal and External Storage

artsoft

Active Member
Licensed User
Longtime User
Hi folks!
Happy new year 2022 :)

After update my Redmi Note 10 Pro (Android 11) my app only shows Internal Memory and External Storage (SD card) while trying to pick a file.
SDK-Version is 30 and I am using FileProvider technic as well.

I try a lot of examples from here which should also show other possibilties to pick files (i. e. One Drive, Google Drive, other file managers installed on my phone). All these possibilities I could use some weeks ago without having any troubles or mistakes.

I can only choose between

1. internal memory and
2. external sdcard memory


to pick a file - while using the contentchooser.

Do I need an update from contentChooser or do I need additional entries or adds in my Manifest file?

I really need help.

Thanks in advance.
 

artsoft

Active Member
Licensed User
Longtime User
There nothing that you can do to control the behavior of ContentChooser. It is an OS feature and it should show all supported providers.

Thanks, Erel, for the quick answer!

I am surprised now, because in the past the content chooser already could provide the "other" pickfile possibilities before I made an update on my REDMI phone.

Therefore my important question:
Is there another way (example code?) to pick a file from dropbox, googledrive, onedrive etc. without using a thirdparty lib?

Eventually by using intents or something like this?

Regards
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is there another way (example code?) to pick a file from dropbox, googledrive, onedrive etc. without using a thirdparty lib?
It does work with ContentChooser. On my Device (Samsung S10) i can get any File from Dropbox (Dropboxapp must be installed on device to provide a Contentprovider) or GoogleDrive (Driveapp must be instaled on device to provide a Contentprovider). Or even Microsofts Drive (if the app is installed and provide a contentoprovider.

Logger connected to: xxxxxx
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
CC_Result(true, Dir: ContentDir, Filename: content://com.dropbox.product.android.dbapp.document_provider.documents/document/L3NhZi8xL2NvbnRlbnQlM0ElMkYlMkZjb20uZHJvcGJveC5hbmRyb2lkLkRyb3Bib3glMkZtZXRh%0AZGF0YSUyRkRhdGVpYW5mcmFnZW4lMkZEZXJMYWNraWVydW5nc2JlYXVmdHJhZ3RlJTJGRG9uTWFu%0AZnJlZF9kaWdpdC50dGYvJTVCNjAlMkMlMjAxMjclMkMlMjA1JTJDJTIwLTI3JTJDJTIwLTc1JTJD%0AJTIwOTUlMkMlMjAtNzUlMkMlMjAxMDMlMkMlMjAtMTMlMkMlMjAyNCUyQyUyMC01JTJDJTIwMTIy%0AJTJDJTIwOTclMkMlMjAxMTglMkMlMjAtNzUlMkMlMjA2JTJDJTIwMjAlMkMlMjAxMDIlMkMlMjAz%0ANCUyQyUyMDMxJTJDJTIwLTEyNyUyQyUyMDc5JTJDJTIwNDglMkMlMjAtMzIlMkMlMjA4NSUyQyUy%0AMC02MCUyQyUyMDI5JTJDJTIwLTk0JTJDJTIwLTkxJTJDJTIwLTEyMSUyQyUyMC02MCUyQyUyMDY0%0AJTVE%0A)
** Activity (main) Resume **
 

Attachments

  • ContentChooserExample.zip
    9.4 KB · Views: 170
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
It does work with ContentChooser. On my Device (Samsung S10) i can get any File from Dropbox (Dropboxapp must be installed on device to provide a Contentprovider) or GoogleDrive (Driveapp must be instaled on device to provide a Contentprovider). Or even Microsofts Drive (if the app is installed and provide a contentoprovider.

Hi Manfred!
Sorry for my late answer and thanks a lot for your help.

Unfortunately
the ContentChooser doesnt work properly on my REDMI Note 10 Pro.

It works perfectly on my Samsung S6Edge. And it seems that on all Samsung this works perfectly: On Samsung smartphones I can choose all kind of data files manager (also cloud files manager like GoogleDrive, OneDrive, and so on) in order to select a file.

But the same code (or better: the same app) running on my REDMI Note 10Pro provides only a simple folder selection for my two drives:

1. the internal smartphone storage and
2. the external storage of my inserted SD card.

No other possibility of choosing files from other file manager is provided there!!! :(

This makes me very sad and also angry, because the REDMI phone is my main smartphone.

I also called the "show" method of the ContentChooser with mimetype */* ... but no success: always same effect!

So anybody here, who could help as well?

Thanks so much. Regard!

__________________________________________________

Update:
This is what I see after calling "show" method of ContentChooser (on REDMI Note 10Pro):

IMG_20220108_011153.jpg


Nothing more..... :-(
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Try this: Under developer options deactivate "MIUI optimizations". Had a similar problem on my 10T Pro. CC didn't work at all and other apps couldn't add attachements (is fixed now).

Hey, hey, hey!!!!

This helped! Thanks a lot ?
Now I can see all my options (cloud manager, files manager and so on).

* * * YOU MADE MY DAY * * *

___________________________________________________

UPDATE: ATTENTION! This was not a good solution! Please be careful by changing the MIUI optimization settings!!!
SEE BELOW!!!
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Grrrr...... Unfortunately, I was happy too soon:

While debugging my app, I saw that the callback method from contentchooser is called but not handled properly:

2022-01-09 14_06_29-B4A.png


So there is no way to check the boolean state of the variable "Success" yet - given wihtin the callback method.


Perhaps, this could be a side effect from setting above "MUI optimizations"???

Why this happens now?? I dont know...
The Callback method is really called - but why without value settings of all parameters there?
Parameter "Dir" and parameter "Filename" are also not set... :-(

Now again being sad.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You don't show all your code but the usual way of getting ContentChooser result is using a Resumable Sub as below taken from Erel's text editor example
B4X:
Public Sub Load As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    'cc.Show("text/*", "Choose text file")
    cc.Show("application/octet-stream", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
You don't show all your code but the usual way of getting ContentChooser result is using a Resumable Sub as below taken from Erel's text editor example
B4X:
Public Sub Load As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    'cc.Show("text/*", "Choose text file")
    cc.Show("application/octet-stream", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub


Yes, you are right!

The "cc" in your code is the name of the callback method. In my case the name is "zipChooser" instead of "cc".

Therefore my callback method is also called.

But, ok, I will try to transform my code in order to have the same calling convention as you.

Will give feedback soon...
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Feedback:

I transformed my code as described above.


All 3 parameters (Success, Dir and Filename) are not set. I see this in the watcher window of the Debugger.

But in this case the parameter "Success" is always evaluated as "false":

2022-01-09 15_09_14-B4A.png


After selecting a file (in my case: a ZIP file (see mime type above)) the value of "Success" is again and always empty!

? :(:confused:

Thanks for your help!

Any other idea?
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Question:

Comes the ContentChooser automatically with B4A?
Means: An internal lib?

Regards.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Comes the ContentChooser automatically with B4A?
Means: An internal lib?
Yes. It's in the ContentResolver library.

Try Log(...) the values in Release mode just to be sure it's not the debugger. You need to add
#BridgeLogger: True
to the Project Attributes in Main.
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Try this: Under developer options deactivate "MIUI optimizations". Had a similar problem on my 10T Pro. CC didn't work at all and other apps couldn't add attachements (is fixed now).

Hi!

What is right now????

I found this thread:

https://www.b4x.com/android/forum/t...-newer-xiaomi-devices-here-mi-10t-pro.132349/

You wrote there, that we should ENABLE this developer option and not DISABLE it, as you wrote above in this thread!!!

So what is right now?


2022-01-09 15_29_58-[solved]Content Chooser fails on newer Xiaomi devices (here_ Mi 10t Pro) _...png


After disabling this as you said: I unfortunately see now many errors on my smartphone!!!

? Many of my apps cannot access my contact names - stored in my smartpgone.

In example: In Whatsapp I can only see the phone numbers but not the names of the contacts.

This was not a good tip:

2022-01-09 15_40_34-ContentChooser only shows Internal and External Storage _ B4X Programming ...png


Now waiting on your feedback!
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
There nothing that you can do to control the behavior of ContentChooser. It is an OS feature and it should show all supported providers.
Hi Erel!

In the past you provided the following link to b4a GitHub Code:

https://github.com/AnywhereSoftware...rc/anywheresoftware/b4a/phone/Phone.java#L846

In the code in the class ContentChooser there is a condition which checks the status of the schemes:

Settings the Dir and Filename:
ion = new IOnActivityResult() {
                @Override
                public void ResultArrived(int resultCode, Intent intent) {
                    String Dir = null, File = null;
                    if (resultCode == Activity.RESULT_OK && intent != null && intent.getData() != null) {
                        try {
                            Uri uri = intent.getData();
                            String scheme = uri.getScheme();
                            if (ContentResolver.SCHEME_FILE.equals(scheme)) {
                                Dir = "";
                                File = uri.getPath();
                            }
                            else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
                                Dir = anywheresoftware.b4a.objects.streams.File.ContentDir;
                                File = uri.toString();
                            }

                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                    ion = null;
                    if (Dir != null && File != null) {
                        ba.raiseEvent(ContentChooser.this, eventName + "_result", true, Dir, File);
                    }
                    else {
                        ba.raiseEvent(ContentChooser.this, eventName + "_result", false, "", "");
                    }
                }
            };

I guess that the Show method checks not all scheme states in case of MIUI 12 Android 11. So the default values for Dir and Filename remains NULL.

The content chooser works with Intent mechanism. So I guess I can try also to work with Intent in order to open and read a ZIP file from internal storage, external storage (SD card) and from cloud file managers.

What you mean?
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
This code has nothing to do with this question. It only runs after the user selected the remote resource.

Unfortunately yes :( ... you are right. I see it now: The IOnActivityResult comes after the user selected the file.

I will try to make some experiments with Intent in order to see better what happens here on such smartphones.

Thanks, Erel.
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Found this on

https://issueexplorer.com/issue/CanHub/Android-Image-Cropper/253

[BUG] - MIUI (Xiaomi) cant pick image from gallery


2022-01-10 11_13_53-[BUG] - MIUI (Xiaomi) cant pick image from gallery - CanHub_Android-Image-...png


I think this is the reason why I cant read the selected file after choose it . See above!

So, in sum we have two problems:

1. The ContractChooser doesn't work properly and only shows memory storages instead of additional cloud file manager.

2. After disabling MIUI optimizations in the DEVELOPER SETTINGS, the cloud file manager options are provided, but after selecting a file the content chooser gets a RESULT_CANCELED instead of a RESULT_OK.

This is a heavy bug since many, many months on my opinion and I am wondering why MIUI didn't react on it until today.
 
Last edited:
Upvote 0
Top