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

android: request camera permission for inputs #2033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vaetas
Copy link

@vaetas vaetas commented Feb 20, 2024

This PR tried to implement requesting user permissions on Android when the input field contains capture param. Requesting camera permission on app startup is not the best UX. This PR tries to delay the permission request until the user actually requires this action.

Testing and Review Notes

You can pass this URL with into the example project WebView: https://12t031.csb.app/

One input is with capture while the other one is regular.

Clicking on capture input should on Android request permissions. When the request is either accepted or denied then the file picker is resumed. When user accepts the permission the file picker contains the option to take a picture with camera.

To Do

I don't regularly touch Java code and there is high chance this is not the best approach. However, this feature is important for me. Let me know if there are any changes need so it could be possibly merged and published.

Thank you!

@@ -126,12 +126,35 @@ public InAppWebViewChromeClient(@NonNull final InAppWebViewFlutterPlugin plugin,
this.inAppBrowserDelegate.getActivityResultListeners().add(this);
}

if (plugin.registrar != null)
if (plugin.registrar != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the brackets

@@ -126,12 +126,35 @@ public InAppWebViewChromeClient(@NonNull final InAppWebViewFlutterPlugin plugin,
this.inAppBrowserDelegate.getActivityResultListeners().add(this);
}

if (plugin.registrar != null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplication of line

// Request camera permission first. The picker intent will be started once the
// permission is either granted or denied.
if (captureEnabled && needsCameraPermission() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getActivity().requestPermissions(new String[]{Manifest.permission.CAMERA}, CAMERA_PICKER);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add permission for gallery and local files.

@faaqi
Copy link

faaqi commented May 7, 2024

Hi @vaetas @balajiks-dev

Can u suggest any solution for this issue?

2108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants