【问题标题】:Cannot connect to camera service android emulator无法连接到相机服务安卓模拟器
【发布时间】:2013-11-13 23:43:49
【问题描述】:

我将模拟器的后置摄像头设置为“模拟”。当我运行我的应用程序时,它会返回运行时异常,提示“无法连接到相机服务”:

camera.open(-1);

这是我的清单:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.protoderma"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="16" />

<uses-permission
android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.example.protoderma.MainActivity"
            android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

谢谢。

【问题讨论】:

    标签: android android-camera android-manifest


    【解决方案1】:

    没有看到更多的代码很难说。但我看到的一个潜在问题是您将 -1 传递给Camera.open();。从docs 中您可以看到,如果有可用的摄像头,则传递的值应始终大于 0。检查 AVD 的配置以查看在相机下拉菜单中是否可以选择除模拟之外的其他内容(即 webcam0)

    【讨论】:

    • 是的,我将 -1 传递给 Camera.open()。谢谢。那么如何只打开后置摄像头呢?
    • Camera.open()(不带任何参数)将获得第一个后置摄像头的参考
    • 不正确,你应该使用 Camera.open(0)
    • “不正确”到底是什么意思?这是docsopen()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多