0

DeviceAdminReceiverを持っていて、ユーザーがパスワードに失敗したときにフロントカメラで写真を撮りたいのですが、エラーが発生しました...

コード:

@Override
    public void onPasswordFailed(Context context, Intent intent) {
        try {
            takePictureNoPreview(context);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

public void takePictureNoPreview(Context context) throws IOException {
        // open back facing camera by default
        Camera myCamera = Camera.open();

        if (myCamera != null) {
            try {
                // set camera parameters if you want to
                // ...

                // here, the unused surface view and holder
                SurfaceView dummy = new SurfaceView(context);
                myCamera.setPreviewDisplay(dummy.getHolder());
                myCamera.startPreview();
                myCamera.takePicture(null, null, getJpegCallback()); //ERROR HERE, LINE 85

            } finally {
                // myCamera.close();

            }

        } else {
            // booo, failed!
        }
    }

    private PictureCallback getJpegCallback() {
        PictureCallback jpeg = new PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                FileOutputStream fos;
                try {
                    fos = new FileOutputStream("test.jpeg");
                    fos.write(data);
                    fos.close();
                } catch (IOException e) {
                    // do something about it
                }
            }
        };
        return jpeg;

    }

エラーログ:

03-20 08:01:35.427: E/AndroidRuntime(26930): FATAL EXCEPTION: main
03-20 08:01:35.427: E/AndroidRuntime(26930): java.lang.RuntimeException: Unable to start receiver packagename.receivername: java.lang.RuntimeException: takePicture failed
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.app.ActivityThread.access$1500(ActivityThread.java:141)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.os.Looper.loop(Looper.java:137)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.app.ActivityThread.main(ActivityThread.java:5041)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at java.lang.reflect.Method.invokeNative(Native Method)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at java.lang.reflect.Method.invoke(Method.java:511)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at dalvik.system.NativeStart.main(Native Method)
03-20 08:01:35.427: E/AndroidRuntime(26930): Caused by: java.lang.RuntimeException: takePicture failed
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.hardware.Camera.native_takePicture(Native Method)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.hardware.Camera.takePicture(Camera.java:1095)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.hardware.Camera.takePicture(Camera.java:1040)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at packagename.receivername.takePictureNoPreview(DeviceAdmin.java:85)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at packagename.receivername.onPasswordFailed(DeviceAdmin.java:49)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.app.admin.DeviceAdminReceiver.onReceive(DeviceAdminReceiver.java:305)
03-20 08:01:35.427: E/AndroidRuntime(26930):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)
03-20 08:01:35.427: E/AndroidRuntime(26930):    ... 10 more

何が問題なのですか?前もって感謝します!

4

1 に答える 1

0

takePictureAndroid 4.0 (少なくとも 1x1 ピクセル) より上の使用済みのサーフェス ビューが必要なため、失敗しました

于 2013-04-16T11:41:42.833 に答える