我试图使用Glass Camera显示捕获的图像并将其显示在ImageView中。
那就是我现在要做的:
public void startCamera()
{
Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(captureIntent, 100);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK && null != data)
{
String photoPath = data.getExtras().getString("picture_file_path");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFile(photoPath, options);
mImageView.setImageBitmap(bitmap);
}
}
但是,位图为空。当我登录photoPath时,它为我提供了一个文件路径,例如:
/mnt/sdcard/DCIM/Camera/20131216_195521_665.jpg
有任何想法吗?
最佳答案
由于拍照后在Glass上进行的处理,在调用onActivityResult
时文件可能未完全写入。
您应该按照FileObserver
javadoc中的说明使用CameraManager
来推迟处理,直到文件准备就绪为止。为此,请FileObserver
观察文件本身上CLOSE_WRITE
事件的给定路径的父目录。 camera developer guide页面底部提供了一个示例。