Android的果冻豆相机返回NULL URI [英] Android Jelly bean camera return null URI

查看:301
本文介绍了Android的果冻豆相机返回NULL URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用相机把我的应用程序的图片,然后裁剪拍摄的图像。

I'm trying to use the camera to take pictures in my app, and then crop the taken images.

一切工作的最新版本为Android,但不为Android 4.4.2奇巧

Everything is working for the recent versions for Android, but not for Android Kitkat 4.4.2.

相机返回一个空URI。

the Camera returns a null URI.

得到URI onActivityReslult:

get the URI onActivityReslult :

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAMERA_CODE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");

            picUri = data.getData();
            Intent i = new Intent(PublierActivity.this, CropActivity.class);
            i.putExtra("Uri", picUri);
            startActivityForResult(i, CROP_CODE);

        }

下面是我如何调用摄像头意图:

Here is how I call the camera intent :

 Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(takePictureIntent, CAMERA_CODE);
                }

有没有什么办法,使对最古老的版本为Android的例外来解决这个问题呢?

is there any way to make an exception for oldest versions for android to resolve this problem ?

推荐答案

从code,它会出现您要使用 ACTION_IM​​AGE_CAPTURE 。在这种情况下,应有的从不乌里— data.getData()应始终返回。如果相机应用恰好返回一个乌里,即可能的是形象,但因为 ACTION_IM​​AGE_CAPTURE 未记录返回乌里,你无法知道什么乌里是方式。

From your code, it would appear that you are trying to use ACTION_IMAGE_CAPTURE. In that case, there should never be a Uridata.getData() should always be returning null. If a camera app happens to return a Uri, that may be the image, but since ACTION_IMAGE_CAPTURE is not documented to return a Uri, you have no way of knowing what that Uri is for.

如果您使用的是 EXTRA_OUTPUT ACTION_IM​​AGE_CAPTURE 意图,你知道哪里有图像应存储,因为你告诉相机应用程序在哪里存储它。需要注意的是有些摄像头应用程序是越野车和未能履行 EXTRA_OUTPUT ,把图像无论他们想要的。

If you are using EXTRA_OUTPUT on the ACTION_IMAGE_CAPTURE Intent, you know where the image should be stored, because you told the camera app where to store it. Note that some camera apps are buggy and fail to honor EXTRA_OUTPUT, putting the image wherever they want.

如果您不使用 EXTRA_OUTPUT ,那么你会得到一个缩略图早在数据额外的费用。

If you are not using EXTRA_OUTPUT, then you will get a thumbnail back in the "data" extra.

另外,请记住,这已经无关,与Android操作系统版本,以及一切与该用户选择使用的相机应用。有成千上万的Andr​​oid设备型号。这些船有几十个,甚至几百个不同的摄像头应用程序的pre-安装。用户可能还选择安装第三方的相机应用。任何这些可能是处理您的请求。

Also, please bear in mind that this has nothing to do with Android OS version, and everything to do with the camera app that the user chooses to use. There are thousands of Android device models. These ship with dozens, if not hundreds, of different camera apps pre-installed. The user might also elect to install a third-party camera app. Any of those could be handling your request.

这篇关于Android的果冻豆相机返回NULL URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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