简体   繁体   English

反应本机 android 用户首次登录时询问相机权限

[英]react native android ask camera permission when user first logs in

I'm not familiar with the react-native app permissions for android and ios. I'm in thihs project which needs camera and audio permissions for videocalls that are already implemented and work fine.我不熟悉 android 和 ios 的 react-native 应用程序权限。我在 thihs 项目中,该项目需要摄像头和音频权限才能实现已经实施并且工作正常的视频通话。

The thing is that currently these permissions are asked the first time the users enters a videocall and that causes delay and bugs on the videocall flow.问题是,目前这些权限是在用户第一次进入视频通话时被询问的,这会导致视频通话流程出现延迟和错误。 I'd like to aks these permissions the first time the users opens the app (they enter first to their profile or the dashboard, the videocall part happens afterwards), like I've seen other apps do.我想在用户第一次打开应用程序时获得这些权限(他们首先进入他们的个人资料或仪表板,视频通话部分随后发生),就像我看到其他应用程序一样。

This is the androidManifest.xml file that handles the permissions.这是处理权限的 androidManifest.xml 文件。 I looked for a way to change when they're asked but I couldn't find anything on the format I'm currently at, and since it's new to me I don't want to change the behaviour completely by accident.当他们被问到时,我正在寻找一种方法来改变,但我找不到关于我目前所处格式的任何东西,而且由于它对我来说是新的,我不想完全意外地改变行为。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.rectnativetemplate">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    

    <application
      android:name=".MainApplication"
      android:usesCleartextTraffic="true"
      android:label="@string/app_name"
      android:requestLegacyExternalStorage="true"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="dev--b45llct.us.auth0.com"
                android:pathPrefix="/android/${applicationId}/callback"
                android:scheme="${applicationId}" />
        </intent-filter>
      </activity>

------------

      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

Is there a way to ask the permissions when the user first enters the app?有没有办法在用户第一次进入应用程序时询问权限? And if it's possible, how can I implement the same behaviour on IOS?如果可能的话,我如何在 IOS 上实现相同的行为?

Use request from PermissionsAndroid .使用来自PermissionsAndroidrequest

const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
  console.log('Camera permission granted');
} else {
  console.log('Camera permission denied');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户在使用react-native-camera时拒绝在android上使用相机的权限时回调 - Callback when user denies permission to use camera on android while using react-native-camera 如何检查用户是否在 React Native Android 中授予了相机权限? - How to check if user has granted camera permission in React Native Android? (Android,React Native)“每次询问”权限仍然返回“被阻止” - (Android, React Native) 'Ask every time' permission still return 'blocked' Android在活动开始时要求相机许可 - Android Ask for Camera Permission On Activity start 如何在反应原生 expo 应用程序(android)中授予相机权限 - How to grant camera permission in react native expo app (android) 如何在 React Native 中请求 LOCATION PERMISSION? - How to ask for LOCATION PERMISSION in React Native? 在与博览会的本机反应中请求读取短信的权限 - Ask permission for read SMS in react native with expo 如何要求用户在 React Native 中启用 MANAGE_EXTERNAL_STORAGE 权限? - How do I ask the user to enable the MANAGE_EXTERNAL_STORAGE permission in React Native? react-native RECEIVE_SMS android权限始终导致&#39;never_ask_again&#39; - react-native RECEIVE_SMS android permission always results 'never_ask_again' 当用户在 React Native 中同意或拒绝时,无法获得 android 权限的回调 - Unable to get callback of android permission when user agrees or rejects in React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM