2

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?

Anton
  • 31
  • 5
  • if your question was closed as a duplicate, vote to reopen it. Do NOT post another duplicate. See https://stackoverflow.com/help/reopen-questions – Jason Jun 16 '22 at 16:53
  • And there are dozens of similar questions already posted. https://www.google.com/search?q=android+file+picker+hide+google+drive+site:stackoverflow.com – Jason Jun 16 '22 at 16:55
  • thanks, @Jason for the navigation, but I'm still can't find necessary answer which is solving this issue. That's why I created this one with desirable example for Xamarin (Android). Please see my 'LinkedIn example' link into description. Any ideas how to achieve this? – Anton Jun 16 '22 at 17:03
  • the questions I saw indicate that its not possible. If LinkedIn is doing it, they may have written their own file picker – Jason Jun 16 '22 at 17:09
  • I should say not only LinkedIn, but Viber, Telegram, and I suspect Facebook as well. In any case, under the hood they found how to hide the Google Drive folder (or icon) from file picker. – Anton Jun 16 '22 at 17:18

1 Answers1

0

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.

Anton
  • 31
  • 5