gpt4 book ai didi

android - 如何获得相机权限android

转载 作者:行者123 更新时间:2023-12-04 23:20:50 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to ask runtime permissions for Camera in Android , Runtime storage permissions

(10 个回答)


去年关闭。




我正在尝试获得在 android 设备上使用 ffmpeg 录制视频的权限。
这是我来自 AndroidManifest.xml 的代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camera">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Camera">
<activity android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity> <activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Here is the specific camera command in 'MainActivity.kt`:
   FFmpeg.execute("-f android_camera -i 0:0 -r 30 -pixel_format bgr0 -t 00:00:05")

这是我的错误:
021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638402! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638403! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1835009! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1835010! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638407! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638408! count 0, type 0
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638402! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638403! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1835009! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1835010! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638407! count 0, type 3
2021-03-22 12:40:41.679 25156-25156/com.example.camera E/ACameraMetadata: filterDurations: malformed duration key 1638408! count 0, type 0
2021-03-22 12:40:41.681 25156-25156/com.example.camera E/ACameraManager: openCamera: connect camera device failed: Status(-8, EX_SERVICE_SPECIFIC): '1: validateClientPermissionsLocked:1041: Caller "" (PID 10222, UID 25156) cannot open camera "0" without camera permission'
2021-03-22 12:40:41.681 25156-25323/com.example.camera E/mobile-ffmpeg: [android_camera @ 0x7267a03e00] Failed to open camera with id 0, error: ACAMERA_ERROR_PERMISSION_DENIED.
2021-03-22 12:40:41.681 25156-25323/com.example.camera E/mobile-ffmpeg: [android_camera @ 0x7267a03e00] Failed to open camera.
2021-03-22 12:40:41.682 25156-25323/com.example.camera E/mobile-ffmpeg: [android_camera @ 0x7267a03e00] Failed to open android_camera.
2021-03-22 12:40:41.682 25156-25323/com.example.camera E/mobile-ffmpeg: 0:0: Generic error in an external library
2021-03-22 12:40:41.707 25156-25156/com.example.camera W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@4ac3524
我究竟做错了什么?我查看的每个来源都建议我在上面添加的权限,但它不起作用。

最佳答案

在使用相机之前,您需要添加这些代码行:

    if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 0);
它将要求用户允许应用程序使用相机。

关于android - 如何获得相机权限android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66750460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com