Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: hide additional permission dialog on Android for file access when not needed #24

Open
koenmuilwijk opened this issue Nov 26, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@koenmuilwijk
Copy link

Version

1.3.0

Environment that reproduces the issue

  • Android 14 device

Is it reproducible in the example application?

Not tested

Reproduction steps

final uploadToken = '...';
final videoId = '...';
final video = await ImagePicker().pickVideo(
      source: ImageSource.gallery, 
      preferredCameraDevice: CameraDevice.front,
      maxDuration: Duration(minutes: 1),
    );
if (video != null) {
  await videouploader.ApiVideoUploader.uploadWithUploadToken(uploadToken, video.path, videoId: videoId);
}

Expected result

When uploading a video an additional permission dialog is displayed on Android. However, in our use case we use ImagePicker for the user to select a file, so we don't need to ask for permission again.

Can we pass a direct link to the selected XFile or File instead of the path as string to prevent this?

Upload video without additional file permission request (already done by ImagePicker().pickVideo(...)).

Actual result

An additional permission request is displayed upon the call to uploadWithUploadToken which doesn't serve any function.

image

Additional context

Android 14 and higher.

Relevant logs output

No response

@koenmuilwijk koenmuilwijk added the bug Something isn't working label Nov 26, 2024
@ThibaultBee
Copy link
Member

ThibaultBee commented Nov 29, 2024

Hi,

On Android 14 a new permission is required to read media. See https://developer.android.com/about/versions/14/changes/partial-photo-video-access

It is just a wild guess but ImagePicker is requesting Manifest.permission.READ_EXTERNAL_STORAGE and the Flutter uploader is requesting Manifest.permission.READ_MEDIA_VIDEO. See https://github.com/apivideo/api.video-flutter-uploader/blob/main/android/src/main/kotlin/video/api/flutter/uploader/utils/Utils.kt#L10
You can check in your built AndroidManifest.xml that you got both permissions. Did you add a read permission (Manifest.permission.READ_EXTERNAL_STORAGE or Manifest.permission.READ_MEDIA_VIDEO) in your application AndroidManifest.xml?

Also, we can't directly use File or XFile because under the hood we are using some native parts. At some point, we will have to get the path from the File or the XFile.

@koenmuilwijk
Copy link
Author

Both permissions are included in the manifest. The weird thing is that it doesn't matter which option is selected in the permission dialog which is triggered by the call to uploadWithUploadToken, it will work regardless. Event when you select 'don't select more' it will just work.

Would it be an option to make the call to the permission dialog optional, so that we can pass in a bool indicating we already retrieved permission to access the file and there is no need to ask for it again?

The current flow is not very user friendly so it'd be great if this can be improved.

@ThibaultBee
Copy link
Member

According to Manifest.permission.READ_EXTERNAL_STORAGE documentation:

Note: Starting in API level 33, this permission has no effect. If your app accesses other apps' media files, request one or more of these permissions instead: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_MEDIA_AUDIO. Learn more about the storage permissions that are associated with media files.

I don't understand why ImagePicker requests Manifest.permission.READ_EXTERNAL_STORAGE and not Manifest.permission.READ_MEDIA_VIDEO.

I don't remember having the same issue in the example app and we are using ImagePicker as well.
Do you manually add permissions in your AndroidManifest.xml?

@koenmuilwijk
Copy link
Author

I just tested with the example app and it basically has the same issue.

  1. Start example Flutter app
  2. Select a video ('video-a.mp4') with the picker (no permission dialog is shown for me)
  3. Now it will start upload and call to uploadWithUploadToken will trigger permission dialog

Few things can happen:

  1. Select Allow all: it will work
  2. Select Allow limited: it will still work, EVEN when you select a different video file ('video-b.mp4')!
  3. Select Don't select more and it will give an error toast, but my gut feeling because uploadWithUploadToken will not continue, but my gut feeling is that it would have worked if the check could be bypassed

Can we make the permission check optional? That'd prevent this issue and make user flow much better.

@ThibaultBee
Copy link
Member

Oh sorry, I understood you got the permission request twice but that's not that.
You just don't want any permission dialog. Right?

@koenmuilwijk
Copy link
Author

Correct, I want a way to prevent it popping up when it's not needed.

@ThibaultBee
Copy link
Member

Oh, the file picker grants a temporary access to the file. I did not know. Indeed there should be a way to NOT request the permission (starting from Android 13). Maybe there is some way to check that we have access to the file, that. would make a simpler API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants