0

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 !!.

McLan
  • 2,552
  • 9
  • 51
  • 85
  • 1
    where is the saving code portion? – Real73 Nov 08 '16 at 10:25
  • 1
    Here is the [link](http://stackoverflow.com/questions/12995185/android-taking-photos-and-saving-them-with-a-custom-name-to-a-custom-destinati) which may help you. – ramkrishna kushwaha Nov 08 '16 at 10:26
  • 1
    post your onActivityResult method – Raghavendra Nov 08 '16 at 10:26
  • @ShahrairNazimReal : the "takePicture" method is where pictures are taken and saved, isn't it ?! – McLan Nov 08 '16 at 10:27
  • @Suda.nese looks like you didn't use the onActivityResult() method? – Raghavendra Nov 08 '16 at 10:30
  • post your all related code you missed the `onActivityResult` method? – Sohail Zahid Nov 08 '16 at 10:32
  • 1
    @Suda.nese yes it is :) .May be you have missing something in `onActivityResult` method.lets add `onActivityResult` – Real73 Nov 08 '16 at 11:02
  • @Raghavendra : You are right ! I don't have a `onActivityResult` method. may you please help me with a sample code for saving the image. question: what is the difference between `startActivityForResult` and `oActivityResult` ?! – McLan Nov 08 '16 at 11:42
  • 1
    @Suda.nese try this http://stackoverflow.com/questions/18010739/android-save-images-in-an-specific-folder – Raghavendra Nov 08 '16 at 11:48
  • @R.k.Kushwaha : Thanks for the link, but my code already opens the camera and takes the shot but I am missing the saving part !! – McLan Nov 08 '16 at 14:22

1 Answers1

1

Did you put the permissions into the Manifest.xml?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Rodrigo Paixão
  • 246
  • 5
  • 12