-
Notifications
You must be signed in to change notification settings - Fork 14
feat(android): implement native camera permission callback with PermissionListener #52
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
feat(android): implement native camera permission callback with PermissionListener #52
Conversation
…ssionListener Implement proper permission callback using PermissionListener and PermissionAwareActivity for Android. Promise now resolves based on actual user response (grant/deny) instead of immediately returning false. Changes: - Add PermissionListener callback to handle permission results - Use PermissionAwareActivity for proper permission flow - Remove react-native-permissions from example app - Update example to use built-in permission methods - Add comprehensive permission documentation to README - Add proper cleanup to prevent memory leaks Achieves feature parity with iOS. Compatible with React Native 0.81+ and Android API 23+. No breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements proper native camera permission callback mechanism for Android to achieve feature parity with iOS. The main purpose is to fix the requestCameraPermission() method so it correctly resolves based on the user's actual permission response instead of immediately returning false.
Key Changes
- Implemented
PermissionListenercallback interface in Android native module with promise storage pattern - Updated example app to use built-in permission methods instead of
react-native-permissionsdependency - Added comprehensive documentation for permission handling APIs with usage examples
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| android/src/main/java/com/pushpendersingh/reactnativescanner/ReactNativeScannerModule.kt | Implements PermissionListener callback and promise storage for proper permission handling |
| example/src/App.tsx | Removes react-native-permissions dependency and uses built-in permission methods |
| README.md | Adds comprehensive API documentation and usage examples for permission methods |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
android/src/main/java/com/pushpendersingh/reactnativescanner/ReactNativeScannerModule.kt
Show resolved
Hide resolved
android/src/main/java/com/pushpendersingh/reactnativescanner/ReactNativeScannerModule.kt
Outdated
Show resolved
Hide resolved
- Add explicit import for PermissionAwareActivity - Replace fully qualified class name with imported reference - Improve code readability and follow Kotlin conventions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
android/src/main/java/com/pushpendersingh/reactnativescanner/ReactNativeScannerModule.kt
Show resolved
Hide resolved
android/src/main/java/com/pushpendersingh/reactnativescanner/ReactNativeScannerModule.kt
Show resolved
Hide resolved
android/src/main/java/com/pushpendersingh/reactnativescanner/ReactNativeScannerModule.kt
Show resolved
Hide resolved
- Add check to reject new requests while one is pending - Prevent promise overwriting that causes hanging promises - Return clear error message for concurrent requests - Ensure all callers receive a response
- Validate that permissions array contains CAMERA permission - Prevent incorrect permission grant due to array mismatch - Add security check: permissions[0] == Manifest.permission.CAMERA - Ensure only camera permission results are processed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
🎯 Overview
Implements proper native camera permission callback mechanism for Android to achieve feature parity with iOS. The
requestCameraPermission()method now correctly resolves based on the user's actual permission response instead of immediately returningfalse.📋 Changes
Android Native Module
PermissionListenercallback interface for handling permission resultsActivityCompat.requestPermissions()toPermissionAwareActivity.requestPermissions()invalidate()to prevent memory leaksBaseActivityEventListenerimplementation that caused build failuresDocumentation
hasCameraPermission()API documentationrequestCameraPermission()API documentationExample App
react-native-permissionsdependency usage fromApp.tsxBarcodeScanner.hasCameraPermission()andBarcodeScanner.requestCameraPermission()🔧 Technical Details
Implementation Pattern
Before (Broken):
After (Fixed):
Key Benefits
trueif granted,falseif denied)react-native-permissionsinvalidate()📱 Usage Example
🧪 Testing
Build Verification
yarn androidpasses)Manual Testing
requestCameraPermission()is calledtruewhen user grants permissionfalsewhen user denies permissionhasCameraPermission()correctly returns permission statusTest Commands
🚀 Breaking Changes
None. This is a bug fix that makes the Android implementation work as originally intended.
Migration Guide
No migration needed. If you were using
react-native-permissionsas a workaround, you can now remove it:📄 Files Changed
android/src/main/java/com/reactnativescanner/ReactNativeScannerModule.kt- Core implementationREADME.md- Added comprehensive documentation and examplesexample/src/App.tsx- Updated to use built-in permission methodsexample/Podfile.lock- CocoaPods dependency update (iOS)📸 Related Issues
Fixes the issue where
requestCameraPermission()on Android always returnedfalseimmediately instead of waiting for user response.✅ Checklist