在 ACTION_IMAGE_CAPTURE 活动中拍摄照片后立即开始编辑活动

发布于 2024-11-27 21:56:52 字数 1243 浏览 1 评论 0原文

首先,我启动相机应用程序来拍摄照片。完成后,我将图像路径放入 extra 以启动编辑视图活动。当我执行此活动时,我发现它总是在拍照后返回到此活动,然后开始编辑活动。如何避免在从相机视图拍摄照片后立即返回此活动并开始编辑活动?

public void onSnapBtnClick(View v ) {
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    mImagePath = createImagePath();
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mImagePath)));
    startActivityForResult(intent, ACTIVITY_SNAP);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == ACTIVITY_SNAP && resultCode == Activity.RESULT_OK) {
    File fi = null;
    try {
    fi = new File(mImagePath);
    } catch (Exception ex) {
    Log.w(Config.LOGTAG, "mImagePath not exist " + mImagePath);
    }

    if (fi != null && fi.exists()) {

    String randomId = UUID.randomUUID().toString();
    new ImageUploadAsynTask().execute(randomId);
    Intent editIntent = new Intent(this, ShopinionEditTextActivity.class);
    editIntent.putExtra(GeatteDBAdapter.KEY_IMAGE_PATH, mImagePath);
    editIntent.putExtra(Config.EXTRA_IMAGE_RANDOM_ID, randomId);
    startActivity(editIntent);
    } else {
    Log.w(Config.LOGTAG, "file not exist or file is null");
    }

} 
}

First, I launch the camera app to capture picture. Once it is done, I put the image path to extra to launch a edit view activity. When I execute this activity, I found it always return to this activity after picture taken and then start the edit activity. How could I avoid to come back to this activity and start the edit activity right after the picture is taken from camera view?

public void onSnapBtnClick(View v ) {
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    mImagePath = createImagePath();
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mImagePath)));
    startActivityForResult(intent, ACTIVITY_SNAP);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == ACTIVITY_SNAP && resultCode == Activity.RESULT_OK) {
    File fi = null;
    try {
    fi = new File(mImagePath);
    } catch (Exception ex) {
    Log.w(Config.LOGTAG, "mImagePath not exist " + mImagePath);
    }

    if (fi != null && fi.exists()) {

    String randomId = UUID.randomUUID().toString();
    new ImageUploadAsynTask().execute(randomId);
    Intent editIntent = new Intent(this, ShopinionEditTextActivity.class);
    editIntent.putExtra(GeatteDBAdapter.KEY_IMAGE_PATH, mImagePath);
    editIntent.putExtra(Config.EXTRA_IMAGE_RANDOM_ID, randomId);
    startActivity(editIntent);
    } else {
    Log.w(Config.LOGTAG, "file not exist or file is null");
    }

} 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-12-04 21:56:52

我相信这是不可能的,因为您正在启动一个您无法控制的单独的应用程序活动。相反,请执行以下操作:

从您的家庭 Activity 中启动 EditActivity。 EditActivity 将包含在 onCreate 中使用 startActivityForResult() 立即启动相机应用程序的代码;如果您在 onCreate 方法中启动另一个 Activity,用户应该无法看到该 Activity。

在 EditActivity 的 onActivityResult 中让它检查返回代码,并执行您需要的任何操作。如果照片拍摄成功,请继续使用“编辑”活动。如果没有,请完成并返回家庭活动。

I belive this is impossible because you are launching a seperate app activity which you have no control over. Instead, do this:

From your home activity, launch the EditActivity. The EditActivity will have code that immediately in the onCreate launches the camera app using startActivityForResult(); The user should not be able to see the activity if you launch another one in the onCreate method.

In the EditActivity's onActivityResult have it check the return code, and do whatever you need. If the picture was taken successfully, continue using the Edit activity. IF not, finish and go back to the home activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文