我的表现: uses-permission android:name =" android.permission.CAMERA" uses-feature android:name =" android.hardware.camera" uses-feature android:name =" android.hardware.camera.autofocus"
我的logcat(REDMI,SONY Xperia,Samsung S6,Samsung Note3):
-LOGCAT of REDMI android 4.2.2: E / AndroidRuntime(2889):at java.lang.Thread.run(Thread.java:838) E / AndroidRuntime(4105):致命异常:主要 E / AndroidRuntime(4105):java.lang.RuntimeException:无法创建服务 com.video.MyService:java.lang.RuntimeException:无法连接到摄像头服务
- SONY Xperia android 5.0.2的更新LOGCAT I /处理(4492):发送信号。 PID:4492 SIG:9 W / ResourceType(4857):找到多个库表,忽略... V / MyActivity(4857):找到相机 W / CameraBase(4857):相机服务死了! W / CameraBase(4857):连接到摄像机时发生错误:0 电子邮件/视频(4857):无法打开相机 W / System.err(4857):java.lang.RuntimeException:无法连接到摄像头服务 W / System.err(4857):在android.hardware.Camera。(Camera.java:520) W / System.err(4857):在android.hardware.Camera.open(Camera.java:361) W / System.err(4857):at com.video.MyService.safeCameraOpen(MyService.java:151) W / System.err(4857):at com.video.MyService.onCreate(MyService.java:92) W / System.err(4857):在android.app.ActivityThread.handleCreateService(ActivityThread.java:2785) W / System.err(4857):在android.app.ActivityThread.access $ 1800(ActivityThread.java:149) W / System.err(4857):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1407) W / System.err(4857):在android.os.Handler.dispatchMessage(Handler.java:102) W / System.err(4857):在android.os.Looper.loop(Looper.java:211) W / System.err(4857):在android.app.ActivityThread.main(ActivityThread.java:5333) W / System.err(4857):at java.lang.reflect.Method.invoke(Native Method) W / System.err(4857):at java.lang.reflect.Method.invoke(Method.java:372) W / System.err(4857):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1016) W / System.err(4857):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) D / AndroidRuntime(4857):关闭VM E / AndroidRuntime(4857):致命异常:主要 E / AndroidRuntime(4857):进程:com.video,PID:4857 E / AndroidRuntime(4857):java.lang.RuntimeException:无法创建服务com.video.MyService:java.lang.NullPointerException:尝试调用虚方法' void android.hardware.Camera.setPreviewTexture(android.graphics .SurfaceTexture)'在> null对象引用
上-LOGCAT三星Note3 android 4.3 E / MediaRecorder(31528):启动失败:-19 W / dalvikvm(31528):threadid = 14:线程退出,未捕获异常(group = 0x417fc898) --------- / dev / log / system的开头 E / AndroidRuntime(31528):致命异常:线程-2241 E / AndroidRuntime(31528):java.lang.RuntimeException:start failed。
LOGCAT三星S6 D / OpenGLRenderer(27352):渲染请求的脏区:true D / PhoneWindow(27352): FMB isFloatingMenuEnabled mFloatingMenuBtn:null D / PhoneWindow(27352): FMB isFloatingMenuEnabled返回false D / libEGL(27352):已加载/vendor/lib64/egl/libGLES_mali.so I / OpenGLRenderer(27352):初始化的EGL,版本1.4 I / OpenGLRenderer(27352):为上下文启用HWUI保护,& this = 0x7f73cbd1a0,& mEglDisplay = 1,& mEglConfig = 1866187440 D / OpenGLRenderer(27352):获得最大纹理大小。 GL_MAX_TEXTURE_SIZE是8192 D / OpenGLRenderer(27352):启用调试模式0 D / mali_winsys(27352):new_window_surface返回0x3000,[1440x2560] -format:1 I / LoadedApk(27352):getClassLoader:dalvik.system.PathClassLoader [DexPathList [[zip file] E / SELinux(27352):[DEBUG] get_category:变量seinfo:默认灵敏度:NULL,cateogry:NULL D / TimaKeyStoreProvider(27352):TimaSignature不可用 D / ActivityThread(27352):添加了TimaKeyStore提供程序 ---------系统的开头 D / LoadedApk(27352):android.app.ActivityThread@fde5c5f强制的getResources? false needsResourceUpdate?false I / InjectionManager(27352):里面的getClassLibPath + mLibMap {0 =,1 =} D / AssetManager(27352):addAssetPath path = / data / app / com.video-1 / base.apkmapset为0 D / AssetManager(27352):addAssetPath path = / data / app / com.video-1 / base.apk,mapOffset = 0 D / LoadedApk(27352):android.app.ActivityThread@fde5c5f强制的getResources? false needsResourceUpdate?false I / LoadedApk(27352):getClassLoader:null I / InjectionManager(27352):内部getClassLibPath调用者 I / LoadedApk(27352):classLibPath :, mActivityThread.mCoreFeatureClassLoader:null D / InjectionManager(27352):InjectionManager I / Choreographer(27352):跳过39帧!应用程序可能在其主线程上做了太多工作。 I / LoadedApk(27352):getClassLoader:dalvik.system.PathClassLoader [DexPathList [[zip file" /data/app/com.video-1/base.apk"],nativeLibraryDirectories = [/ vendor / lib64 ,/ system / lib64]]] E / BufferQueueProducer(27352):[unnamed-27352-0] dequeueBuffer:min undequeued buffer count(2)exceeded(dequeued = 8 undequeued = 0) E / BufferQueueProducer(27352):[unnamed-27352-0] dequeueBuffer:min undequeued buffer count(2)exceeded(dequeued = 8 undequeued = 0) E / BufferQueueProducer(27352):[unnamed-27352-0] dequeueBuffer:超出min未加队列的缓冲区计数(2)(dequeued = 7 undequeued = 1) E / BufferQueueProducer(27352):[unnamed-27352-0] dequeueBuffer:超出min未加队列的缓冲区计数(2)(dequeued = 7 undequeued = 1) E / BufferQueueProducer(27352):[unnamed-27352-0] dequeueBuffer:min unqueued> buffer count(2)exceeded(dequeued = 7 undequeued = 1)
这是我的代码:
public class MyService extends Service{
private Camera mcamera;
@SuppressLint("NewApi") @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void
onCreate() {
mcamera=Camera.open();
try {
mcamera.setPreviewTexture(new SurfaceTexture(0));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mcamera.startPreview();
public void capture(){
mcamera.takePicture(null, null,null,mPicture);
}
PictureCallback mPicture = new PictureCallback(){
@Override
public void onPictureTaken(byte[] data, Camera mcamera) {
(...)
};
(...)
答案 0 :(得分:0)
我认为你的清单包含所有必要的权限?当我遇到类似问题时,解决方案是必须异步加载任务。如果是这种情况,您需要AsyncTask
来打开相机或拍摄照片或两者兼而有之。
我希望这些输入有所帮助。