我正在尝试拍照,但是使用我的代码,需要通过“点击”手势确认图片。
这是我的代码:
private void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE_REQUEST && resultCode == RESULT_OK) {
String thumbnailPath = data.getStringExtra(Intents.EXTRA_THUMBNAIL_FILE_PATH);
String picturePath = data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);
processPictureWhenReady(picturePath);
// TODO: Show the thumbnail to the user while the full picture is being
// processed.
}
else{
takePicture();
}
super.onActivityResult(requestCode, resultCode, data);
}
我看到这篇文章:
Is it possible to take a photo using Google Glass without "tap to accept"?
但是如果没有Tap,我无法获得图片。 有什么例子吗?
谢谢!
答案 0 :(得分:0)
为此,您需要添加一个启用手势检测的机制。在你的情况下,它是TAP手势。我建议将这段代码放在takePicture()
方法中:
@Override
public boolean onKeyDown(int keycode, KeyEvent event) {
if (keycode == KeyEvent.KEYCODE_DPAD_CENTER) {
// user tapped touchpad, do something
return true;
}
...
return super.onKeyDown(keycode, event);
}
这样,只有在点击玻璃上时才能拍照,因此确认。有关详细信息,请查看此document。