@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foto);
Intent intentFotocamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); //creo un timestamp univoco
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
imagesFolder.mkdirs(); //creo un nuovo album
File image = new File(imagesFolder, "QR_" + timeStamp + ".png"); //concateno
Uri uriSavedImage = Uri.fromFile(image);
intentFotocamera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(intentFotocamera, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
现在,当用户按下照片确认按钮(然后在本地保存)时,我想创建一个新活动,因为我想在我的应用程序中打印这张照片。
如何创建新活动?
答案 0 :(得分:2)
在覆盖方法onActivityResult()中启动新活动。
https://developer.android.com/training/basics/intents/result.html
示例:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
// Check which request we're responding to
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was selected.
// Do something with the contact here (bigger example below)
}
}
}
答案 1 :(得分:1)
您想要打开新活动并显示最近拍摄的照片吗?
以下是如何做到这一点。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
"handle here"
}
} catch (Exception ex) {
}
}