我正在尝试使用此应用程序,该应用程序提供使用前置摄像头的功能。我已经按照很多教程重写了代码,遍布网络搜索了3-4次代码为什么我得到了这个异常,更改了我的清单中权限和功能的使用情况,我无法遇到解决方案,我真的很感激一些帮助,我真的被困在这里,
这是我的清单:
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" />
我用来调用相机的活动中的方法
public android.hardware.Camera openCam(){
int cameraCount = 0;
android.hardware.Camera cam = null;
android.hardware.Camera.CameraInfo cameraInfo = new android.hardware.Camera.CameraInfo();
cameraCount = android.hardware.Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx<cameraCount; camIdx++) {
android.hardware.Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {
try {
cam = android.hardware.Camera.open(camIdx);
} catch (RuntimeException e) {
Log.e("Your_TAG", "Camera failed to open: " + e.getLocalizedMessage());
}
}
}
return cam;
}
调用相同活动中的方法
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.actionSelfie:
openCam();
return true;
}
return super.onOptionsItemSelected(item);
}
这是我的堆栈跟踪:
08-15 16:36:38.759:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.762:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.764:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.768:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.782:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.782:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.783:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.783:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.784:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.787:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.787:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.788:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.788:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.790:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.792:I / SurfaceTextureClient(7134):[STC :: queueBuffer](this:0x5dfea768)fps:0.63,dur:9547.63,max:8855.17,min:65.20 08-15 16:36:38.792:I / SurfaceTextureClient(7134):[STC :: queueBuffer] this:0x5dfea768,api:1,上次排队时间已过:8855.17 08-15 16:36:38.795:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.796:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.800:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.801:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.826:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.827:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.838:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.838:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.854:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.855:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.903:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.904:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.904:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.905:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.905:V / Provider / Settings(7134):来自设置缓存,name = sound_effects_enabled,value = 1 08-15 16:36:38.915:D / Camera-JNI(7134):getNumberOfCameras + 08-15 16:36:38.916:D / Camera-JNI(7134):getNumberOfCameras(2) - 08-15 16:36:38.916:D / ServiceManager(7134):服务名称为audio 08-15 16:36:38.917:D / ServiceManager(7134):服务名称为audio 08-15 16:36:38.920:E / Your_TAG(7134):相机无法打开:无法连接到相机服务 08-15 16:36:38.922:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.922:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.922:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.923:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.923:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.923:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.923:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.924:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.926:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:36:38.926:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.893:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.896:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.900:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.931:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.931:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.932:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.935:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.936:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.936:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.936:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.937:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.937:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.937:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.940:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.940:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.940:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.940:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.942:W / Trace(7134):来自nativeGetEnabledTags的意外值:0 08-15 16:37:38.995:V / InputMethodManager(7134):START INPUT:com.android.internal.policy.impl.PhoneWindow $ DecorView {429a4e40 VE .... R ....... 0,0 -480,854} ic = null tba=android.view.inputmethod.EditorInfo@42982f60 controlFlags =#100 08-15 16:37:39.011:V / InputMethodManager(7134):开始输入:Bind result=InputBindResult{com.android.internal.view.IInputMethodSession$Stub$Proxy@429837b8 com.android.inputmethod.latin / .LatinIME# 83}