我在我的应用中集成了相机。当我在模拟器上运行时,下面的代码工作正常,我在亚行选择了网络摄像头作为我的相机。但是当我在像Nexus 7这样的实际设备上运行时,我的应用程序无法检测到相机。相机在这款平板电脑上工作正常但不在我的应用中。
CameraActivity.java
//I've imported hardware camera class
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
// Some activity code
if (!getPackageManager().
hasSystemFeature(PackageManager.FEATURE_CAMERA)) { // Issue is coming from here.
Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
.show();
} else {
cameraId = findFrontFacingCamera();
if (cameraId < 0) {
Toast.makeText(this, "No front facing camera found.",
Toast.LENGTH_LONG).show();
} else {
camera = Camera.open(cameraId);
}
}
Mainfest.xml
<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>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
答案 0 :(得分:0)
在此处进行更改
尝试检查:
hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)
相反:
hasSystemFeature(PackageManager.FEATURE_CAMERA)
Nexus 7只有前置摄像头。
Android摄像头选择算法默认为后置摄像头。