[英]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 .使用来自PermissionsAndroid的request
。
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.