Android take图像捕获获取空值

Android take图像捕获获取空值,android,image,android-intent,take,Android,Image,Android Intent,Take,我在android上与image caputre合作。我尝试在存储设备上保存图像后拍摄照片并发送图像。有些设备(如LG)会为URI图像返回null。我不知道为什么在LG和三星S4上得到这个值。我工作得很好 代码: 启动照相机意图并创建文件目录: public class PhotoIntentHelper { public static final int YOUR_SELECT_PICTURE_REQUEST_CODE = 4; public Uri outputFileUri

我在android上与image caputre合作。我尝试在存储设备上保存图像后拍摄照片并发送图像。有些设备(如LG)会为URI图像返回null。我不知道为什么在LG和三星S4上得到这个值。我工作得很好

代码:

启动照相机意图并创建文件目录:

public class PhotoIntentHelper
{
    public static final int YOUR_SELECT_PICTURE_REQUEST_CODE = 4;
    public Uri outputFileUri = null;

    public void startCamera(Context ctx)
    {
        generateTimeStampPhotoFileUri(ctx);

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        ((ActivityBaseBar)ctx).startActivityForResult(intent, YOUR_SELECT_PICTURE_REQUEST_CODE);
    }

    private void generateTimeStampPhotoFileUri(Context ctx) 
    { 

        final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
        if(!root.exists())
        {
            root.mkdirs();
        }

        final String fname = "img_"+ System.currentTimeMillis() + ".jpg";
        final File sdImageMainDirectory = new File(root, fname);
        outputFileUri = Uri.fromFile(sdImageMainDirectory);
    }

    public Bitmap imageFromUri()
    {
        String url = outputFileUri.getPath();

        if(url == null || (url != null && url.length() == 0))
        {
            return null;
        }

        //First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(url, options);

        // Calculate inSampleSize, Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        int inSampleSize = 1;

        if (height > 600) 
        {
            inSampleSize = Math.round((float)height / (float)800);
        }
        int expectedWidth = width / inSampleSize;

        if (expectedWidth > 800) 
        {
            //if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
            inSampleSize = Math.round((float)width / (float)600);
        }

        options.inSampleSize = inSampleSize;

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;

        Bitmap bitmap = BitmapFactory.decodeFile(url,
                options); 

        bitmap = ExifUtils.rotateBitmap(url, bitmap);

        return bitmap;
    }
...
}
活动结果代码:

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        Bitmap imageBitmap = null;

        if(resultCode == RESULT_OK)
        {
            if(requestCode == PhotoIntentHelper.YOUR_SELECT_PICTURE_REQUEST_CODE )
            {
                imageBitmap = photoHelper.imageFromUri();
            }
            else
            {
                Toast.makeText(this, "sadasda", Toast.LENGTH_SHORT).show();
                return;
            }
            if(imageBitmap != null)
            {
                //something
            }
            else
            {
                Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
            }

        }
    }
行字符串url=outputFileUri.getPath;返回空异常。
需要帮助。

请尝试几次返回sem null异常。。。为什么?