无法在Android中将onActivityResult RESULT_OK解析为变量? [英] onActivityResult RESULT_OK can not be resolved to a variable in android?

查看:37
本文介绍了无法在Android中将onActivityResult RESULT_OK解析为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在片段中启动相机,但是片段中的onActivityResult无法解析RESULT_OK.我该怎么办?

I am trying to launch camera in fragment but onActivityResult in fragment doesn't resolve RESULT_OK. What should i do?

我正在使用以下方法启动相机

I am launching camera using:

public static final int CAMERA_REQUEST_CODE = 1999;

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);

使用以下方法获取捕获的图像:

get captured image using:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        if (bitmap != null) {
        }
    }
}

我想在当前片段中捕获图像!

and i want captured image in current fragment!

推荐答案

RESULT_OK 是Activity类的常量.在活动"类中,您可以直接访问,但在其他类中,还需要输入类名称(活动性").

RESULT_OK is constant of Activity class. In Activity class you can access directly but in other classes you need to write class name (Activity) also.

使用 Activity.RESULT_OK 而不是RESULT_OK.

Use Activity.RESULT_OK instead of RESULT_OK.

您的情况将是

if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK) {

这篇关于无法在Android中将onActivityResult RESULT_OK解析为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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