[FIXED] Hide (or remove) Google Drive icon (folder) from Android file picker

Issue

I’d like to ask help for the Android file picker.
I need to remove (or hide) Google Drive icon (or ‘My Drive’ icon / or ‘Drive’ icon) from Android file picker.
Please provide samples for Xamarin (C#), desirable, or Java / Kotlin could be useful as well.
I need the same behavior, like LinkedIn file picker has (and many other messengers as well):
please see the:
LinkedIn example

Also, please note, this question / answer is not solving the issue:
Is it possible to hide google drive while using Intent.ACTION_GET_CONTENT in android?

Solution

I found solution when I a little bit reworked this xamarin-samples solution code:
xamarin/xamarin-forms-samples/DependencyService (thanks to David Britch)

The key moment here is: Intent.ActionOpenDocument intent action for the Android picker.
And now with this code:

 public async Task<string> PickFileAsync(FilePickerFileType fileTypeEnum)
    {
        string pickerType = string.Empty;
        string title = string.Empty;
        if (fileTypeEnum == FilePickerFileType.Images)
        {
            pickerType = "image/*";
            title = "Select images";
        }
        else if (fileTypeEnum == FilePickerFileType.Pdf)
        {
            pickerType = "application/pdf";
            title = "Select PDF";
        }
        else if (fileTypeEnum == FilePickerFileType.Videos)
        {
            pickerType = "video/*";
            title = "Select video";
        }
        
        // Define the Intent for getting files
        Intent intent = new(Intent.ActionOpenDocument);
        intent.SetType(pickerType);
        intent.PutExtra(Intent.ExtraLocalOnly, true);

        // Start the file-picker activity (resumes in MainActivity.cs)
        MainActivity.Instance.StartActivityForResult(
            Intent.CreateChooser(intent, title),
            MainActivity.PickFileId);

        // Save the TaskCompletionSource object as a MainActivity property
        MainActivity.Instance.PickFileTaskCompletionSource = new TaskCompletionSource<string>();

        // Return Task result
        return await MainActivity.Instance.PickFileTaskCompletionSource.Task.ConfigureAwait(false);
    }

, I have necessary result, where I don’t have any Google Drives in my files browser:

No Google Drive

Hopefully, my example will help people to avoid Google Drive video files loading during the video files picking with Xamarin / MAUI apps. Which is cause a lot of loading issues. That’s why apps like LinkedIn, Telegram, Viber, Facebook and other mobile apps allow to pick only local device videos from local folders, but not from remote Drives, like Google, to avoid loading issues.

Answered By – Anton

Answer Checked By – Pedro (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published