Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 摄像机数据意图为空_Java_Android - Fatal编程技术网

Java 摄像机数据意图为空

Java 摄像机数据意图为空,java,android,Java,Android,我看到了关于这个问题的其他问题和答案,但没有一个对我有用 我正试图从相机中拍摄一张照片,并将其显示在imageview中。 我还使用了一个Helper类来获得更清晰的代码 以下是Helper类中的代码: 拍照: public static void getphoto(final Activity act, final int int, final Uri uri){ Intent cameraIntent = new Intent("android.media.action.IMAGE_CAP

我看到了关于这个问题的其他问题和答案,但没有一个对我有用

我正试图从相机中拍摄一张照片,并将其显示在imageview中。 我还使用了一个Helper类来获得更清晰的代码

以下是Helper类中的代码:

拍照:

public static void getphoto(final Activity act, final int int, final Uri uri){

Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);  
act.startActivityForResult(cameraIntent, int);

        }
获取路径:

    public static String pathgal(Activity act, Uri uri){

    String[] filePathColumn = {MediaStore.Images.Media.DATA};

    Cursor cursor = act.getContentResolver().query(uri, filePathColumn, null, null, null);
    if (cursor != null) {
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String filePath = cursor.getString(columnIndex);
    cursor.close();

    return filePath;
    }
    return null;

}
获得结果:

if (requestCode == CAMERA_REQUEST) {
        if (resultCode == RESULT_OK) {
            String capturedImageFilePath = Helper.pathgal(act, mCapturedImageURI);
            bmp = Helper.decodeFile(capturedImageFilePath);

            Log.d("******CAMERAAAAAAA*******", "Camera fine 10");

            if(data != null)
            {
                Log.d("******CAMERAAAAAAA*******", "Camera fine 11");

                Helper.showpic(act, id1, bmp);

                Log.d("******CAMERAAAAAAA*******", "Camera fine 12");

            } else if (data == null) {
                Log.d("******CAMERAAAAAAA*******", "Camera fine 13");
                Toast.makeText(act.getApplicationContext(), "Data is Null",
                        Toast.LENGTH_SHORT).show();
            }

        }

}
现在,如果我在一部低级手机(比如HTC wildfire s)上进行测试,一切都正常,我会得到“camera fine 11和12”日志。但如果我在高级手机(如Galaxy s4)上测试它,它会给出“数据为空”和“摄像头正常13”


那么,我应该如何防止在此类设备中获取null呢?

当您在camera intent中传递带有uri的额外参数MediaStore.extra\u输出时,您告诉camera activity将捕获的图像写入该路径,并且它不会在onActivityResult方法中返回位图。因此,您在onActivityResult上的值为空

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //this line
你不妨试试这个

String capturedImageFilePath = Helper.pathgal(act, mCapturedImageURI);
        bmp = Helper.decodeFile(capturedImageFilePath);
if(bmp != null)
  {
    Helper.showpic(act, id1, bmp);
  } else{
      Toast.makeText(act.getApplicationContext(), "bmp is Null",Toast.LENGTH_SHORT).show();
  }

什么是数据?设定在哪里?这是一个意图。Android在onActivityResult中自动命名它。啊,你是指onActivityResult的第三个参数(int,int,Intent)。Android不控制您命名的参数:)是的,您是对的。现在我给出“位图超过vm buget”错误,这是另一个问题。谢谢兄弟。