Android内蔵カメラの取得を回避する意図を使用せずに、カメラ機能を実装しようとしているAndroidアプリを開発しています。
Preview.java を使用して、カメラが画面に表示しているものを表示しています。
public void surfaceCreated(SurfaceHolder holder) {
Mydcamera = Camera.open();
try {
Mydcamera.setPreviewDisplay(holder);
Mydcamera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera arg1) {
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Preview.this.invalidate();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
しかし、アプリを実行するたびに、以下のコード行で強制的に閉じられます
Mydcamera = Camera.open();
エラーログ:
08-14 09:10:57.027: E/AndroidRuntime(2318): java.lang.RuntimeException: Fail to connect to camera service
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.hardware.Camera.native_setup(Native Method)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.hardware.Camera.<init>(Camera.java:294)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.hardware.Camera.open(Camera.java:271)
08-14 09:10:57.027: E/AndroidRuntime(2318): at com.ssn.newcamerademo.Preview.surfaceCreated(Preview.java:45)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.SurfaceView.updateWindow(SurfaceView.java:564)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.SurfaceView.updateWindow(SurfaceView.java:408)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:352)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.View.draw(View.java:6936)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.widget.FrameLayout.draw(FrameLayout.java:357)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.View.draw(View.java:6936)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.widget.FrameLayout.draw(FrameLayout.java:357)
08-14 09:10:57.027: E/AndroidRuntime(2318): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewRoot.draw(ViewRoot.java:1527)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.os.Looper.loop(Looper.java:130)
08-14 09:10:57.027: E/AndroidRuntime(2318): at android.app.ActivityThread.main(ActivityThread.java:3687)
08-14 09:10:57.027: E/AndroidRuntime(2318): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 09:10:57.027: E/AndroidRuntime(2318): at java.lang.reflect.Method.invoke(Method.java:507)
08-14 09:10:57.027: E/AndroidRuntime(2318): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
08-14 09:10:57.027: E/AndroidRuntime(2318): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-14 09:10:57.027: E/AndroidRuntime(2318): at dalvik.system.NativeStart.main(Native Method)
どこが間違っているのかわかりません。助けてください!ありがとう!