拍摄意图后的新活动 [英] New activity after camera intent

查看:74
本文介绍了拍摄意图后的新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

    @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);
}

现在,当用户按下照片确认按钮(然后将其保存在本地)时,我想创建一个新活动,因为我想在我的应用程序中打印这张照片.

Now, when the user presses the photo confirmation button (and then is saved locally) I would like to create a new activity because I want to print this photo in my app.

如何创建新活动?

推荐答案

在覆盖方法onActivityResult()中启动新活动.

In the override method onActivityResult() start the new activity.

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)
    }
}
}

这篇关于拍摄意图后的新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆