public void onPictureTaken(byte[] data, Camera camera) {
Uri imageFileUri =
getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
new ContentValues());
try {
OutputStream imageFileOS =
getContentResolver().openOutputStream(imageFileUri);
imageFileOS.write(data);
imageFileOS.flush();
imageFileOS.close();
Toast t = Toast.makeText(this,"Saved JPEG!", Toast.LENGTH_SHORT);
t.show();
} catch (FileNotFoundException e) {
Toast t = Toast.makeText(this,e.getMessage(), Toast.LENGTH_SHORT);
t.show();
} catch (IOException e) {
Toast t = Toast.makeText(this,e.getMessage(), Toast.LENGTH_SHORT);
t.show();
}
camera.startPreview();
}
}
然而,布局XML稍微有點(diǎn)不同。這個(gè)應(yīng)用程序在一個(gè)包含LinearLayout的FrameLayout中顯示攝像頭預(yù)覽SurfaceView,其中包含TextView來(lái)顯示倒計(jì)時(shí),并且包含Button來(lái)觸發(fā)倒計(jì)時(shí)。該FrameLayout中的所有對(duì)象均左上角對(duì)齊,并且依次堆疊。采用這種方式,TextView和Button均顯示在攝像頭預(yù)覽的頂部。