簡體   English   中英

無法打開攝像頭連接到攝像頭時出錯:0

[英]Cannot open Camera An error occurred while connecting to camera: 0

我開始開發應用程序,我需要使用手機的相機,當我使用Camera.open()方法時,無論是否使用cameraId,它都會返回錯誤“連接到相機時發生錯誤:0”。 我的AndroidManifest.xml是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.telecombretagne.holowater">

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.autofocus" />
    <uses-feature android:name="android.hardware.flash" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".camera"
            android:label="@string/title_activity_camera"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>

我的手機的Android版本是6.0.1,它是BQ Aquaris M5。

提前致謝。

正在運行的棉花糖,需要許可的設備要在運行時設置,這里是從另一個類似的問題,我的答案在這里 :)

來自https://developer.android.com/training/permissions/requesting.html
注意:從Android 6.0(API級別23)開始,用戶可以隨時撤消任何應用的權限,即使應用程序的API級別較低也是如此。 無論您的應用針對什么API級別,您都應該測試您的應用,以驗證它在缺少所需權限時是否正常運行。

除了清單中設置的權限之外,您還需要請求/檢查運行時的權限。 您可以使用示例代碼,或者......


快速解決方案

轉到設置 - >應用程序 - >(您的應用程序名稱) - >權限並啟用相機權限。 完成,但不推薦用於最終產品

然后再試一次你的應用。 應該現在正在工作:D

嘗試也添加相機ID,如

Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM