如何在onPictureTaken()执行并返回时收到通知?

问题描述 投票:-2回答:1

我有一个类变量photoPath,它被初始化为null。

private static string photoPath = null;

然后在onPictureTaken的主体内部,为该变量分配一定的String值。

final PictureCallback pictureCallback = new PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        Log.i(TAG, "onPictureTaken() of Camera.PictureCallback called.");// check
        ...
        photoPath = aValidPathString;
        ...
    }
}

然后在按钮的单击监听器中,我调用了Camera.takePicture()方法。之后,我已经注销了photoPath的值。 photoPath的这个值在输出中证明是null;并且onPictureTaken() of Camera.PictureCallback called.从不在输出中打印。这意味着在我注销photoPath的值时不会调用onPictureTaken()。

所以我想知道onPictureTaken()何时返回,以便我可以确定onPictureTaken()已被执行,并且我在那时注销photoPath的值。我怎么做?

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.i(TAG, "onClick() of View.OnClickListener called.");// check

        camera.takePicture(null, null, pictureCallback);

                /*while(photoPath==null) {
                    Log.i(TAG, "PHOTO_NAME is null at the moment.");/*
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Log.i(TAG, "Waiting for half a second.");
                        }
                    }, 500);*
                }*/

        Log.i(TAG, photoPath);// check
    }
}
android android-camera
1个回答
0
投票

等待从你的pictureCallback接收回调qazxsw poi:

onCaptureCompleted
© www.soinside.com 2019 - 2024. All rights reserved.