Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

java - Android Jelly bean camera return null URI

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

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

the Camera returns a null URI.

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);
                }

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...