zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.11k stars 837 forks source link

Android Check Camera Permission Always Return Unavailable #816

Closed BagasNS closed 1 year ago

BagasNS commented 1 year ago

Bug summary

im using real device Samsung S23 FE (Android 13) first try request permission running smoothly, after a while method check() always return unavailable but when i try request permission wihout check() it running well, does check() method really important? here is my sample code

async function getCameraAndroid(params: PermissionParamsType) {
  const checkResult = await check(PERMISSIONS.IOS.CAMERA);
  if (checkResult !== 'denied') {
    return checkResult;
  }

  let rationale: Rationale = {
    title: params.title,
    message: params.message,
    buttonPositive: 'Izinkan',
    buttonNegative: 'Jangan Izinkan'
  }

  return request(PERMISSIONS.ANDROID.CAMERA, rationale)
}

if i comment check method it running well

async function getCameraAndroid(params: PermissionParamsType) {
  // const checkResult = await check(PERMISSIONS.IOS.CAMERA);
  // if (checkResult !== 'denied') {
  //   return checkResult;
  // }

  let rationale: Rationale = {
    title: params.title,
    message: params.message,
    buttonPositive: 'Izinkan',
    buttonNegative: 'Jangan Izinkan'
  }

  return request(PERMISSIONS.ANDROID.CAMERA, rationale)
}

already run ./gradlew clean, uninstall app on real device, re-run metro bundler with --reset-cache, issue still presist

Library version

3.10.0

Environment info

System:
  OS: macOS 13.6
  CPU: (10) arm64 Apple M2 Pro
  Memory: 101.95 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.5.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.8.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.07.24.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.13.0
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 15.0/15A240d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.5
    wanted: 0.72.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

  1. Install lib using yarn And Setup for android
  2. try to check permission camera android

Reproducible sample code

async function getCameraIOS(params: PermissionParamsType) { const checkResult = await check(PERMISSIONS.IOS.CAMERA); if (checkResult !== 'denied') { return checkResult; }

let rationale: Rationale = { title: params.title, message: params.message, buttonPositive: 'Izinkan', buttonNegative: 'Jangan Izinkan' }

return request(PERMISSIONS.ANDROID.CAMERA, rationale) }

async function getCameraAndroid(params: PermissionParamsType) { const checkResult = await check(PERMISSIONS.IOS.CAMERA); if (checkResult !== 'denied') { return checkResult; }

let rationale: Rationale = { title: params.title, message: params.message, buttonPositive: 'Izinkan', buttonNegative: 'Jangan Izinkan' }

return request(PERMISSIONS.ANDROID.CAMERA, rationale) }


- SomeComponent.tsx

<Pressable onPress={async () => { // Check Permission const permissionCamera = await getCamera({ title: 'Akses Kamera Dibutuhkan', message: 'Izinkan akses kamera agar kamu dapat mengambil gambar dengan kamera' }); console.log(permissionCamera) }}

Test Permission

BagasNS commented 1 year ago

here is some video https://github.com/zoontek/react-native-permissions/assets/36254694/53d16f42-b26c-4c86-a175-8acbd6e53884

BagasNS commented 1 year ago

oops some mistake made by me

async function getCameraAndroid(params: PermissionParamsType) {
  const checkResult = await check(PERMISSIONS.IOS.CAMERA); // this is wrong, it must be PERMISSIONS.ANDROID.CAMERA

  if (checkResult !== 'denied') {
    return checkResult;
  }

  let rationale: Rationale = {
    title: params.title,
    message: params.message,
    buttonPositive: 'Izinkan',
    buttonNegative: 'Jangan Izinkan'
  }

  return request(PERMISSIONS.ANDROID.CAMERA, rationale)
}