The camera application does not return to my activity

I want to start the camera app to get the photo, but when I click ok, the camera app is still in the foreground and my activity cannot resume.

That's what I'm doing:

File file = new File(getFilesDir() + File.separator + UUID.randomUUID().toString() + ".jpg"); try { file.createNewFile(); } catch (IOException e) { Toast.makeText(this, R.string.problem_creating_file, Toast.LENGTH_LONG).show(); return; } Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); takePhotoIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivityForResult(takePhotoIntent, REQUEST_CODE_PHOTO); 

And in the manifest:

 <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> 

I found many solutions on the Internet, but no one worked for me :(

0
android android camera
source share
3 answers

You start a third-party activity. Nobody forces the authors of this activity to do everything you are looking for, including:

  • to take a photo
  • saving the image in the requested location
  • immediately returns to your application after the photo is taken.

Many camera apps will do at least the first two of these things. It is hoped that all applications for the camera will take a picture, but probably at least one of them with errors in the implementation of ACTION_IMAGE_CAPTURE .

Therefore, you and your application should not make any assumptions about what a third-party application does when you ask him to take a picture. In particular, you need to know that the user may need to press BACK to leave the camera application and return to yours, depending on the implementation of the user-selected camera application. And it is quite possible that an application with a buggy camera does not even read the BACK button, in which case the user needs to choose the best application for the camera.

+1
source share

Delete this ...

 takePhotoIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
0
source share

If you just need a snapshot, and not one of the weird effects that you have in the camera, you can write a camera class to use in your application so that you can control its functionality.

0
source share

All Articles