McLan
McLan

Reputation: 2688

Android: Camera opens but doesn't save the taken shot, why?

I am trying to take a picture and save it in the Gallary app. So far I managed to write the following piece of code:

public void sendMessages(View view) {
        Intent intent = new Intent(this, MessagingAdapter.class);
        startActivity(intent);
    }

    public void takePicture(View view) {
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri());
        startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
    }


    public Uri getImageUri() {
        picNo++;

        String storageFolderPath = Environment.getExternalStorageDirectory() + "/CameraImages/";
        String fullFileName = storageFolderPath + picNo + ".jpg";
        File newPic = new File(fullFileName);

        Uri outputFileUri = Uri.fromFile(newPic);
        return outputFileUri;
    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == 1)
            return;
        if (requestCode == 3) {
            Uri uri = data.getData();  //YOU GET DATA HERE
        }
    }

It is working and there is no error. However, it doesn't function as I want.

I am testing on Nexus-7 (CynongeMode) . My app opens the camera alright. But after taking the shot, it freezes on the taken image and gives 3 options (the camera app is a built-in app):

  1. Cancel and return from the camera to my app, or
  2. Retake the shot, or
  3. Accept the taken image !

Now, the first two options work but the 3rd option doesn't do anything AT ALL, it just freezes as shown bellow:

enter image description here

What might be the problem and why I canoot save the image ?!


UPDATE

I put a very simple onActivityResult method. But it doesn't even go there (when debugging). However, when I remove the cameraIntent.putExtra line, then it goes to the onActivityResult but again no saved image !!.

Upvotes: 0

Views: 70

Answers (1)

Rodrigo Paixão
Rodrigo Paixão

Reputation: 246

Did you put the permissions into the Manifest.xml?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Upvotes: 1

Related Questions