我有一个类变量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
}
}
答案 0 :(得分:0)
等待从你的pictureCallback接收回调onCaptureCompleted
:
private CameraCaptureSession.CaptureCallback pictureCallback = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
// your picture has been taken
};