Android camera not returning to my app when photo was taken

He cannot even create a folder on the SD card. When the camera takes a photo, it does not respond when I press the OK button. What is wrong with my code?

public static final String MACCHA_PATH = Environment.getExternalStorageDirectory().getPath() + "/Twigit"; public static final String PHOTO_PATH = MACCHA_PATH + "/camera.jpg"; public static boolean takePhoto(Activity activity) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File fileDir = new File(MACCHA_PATH); boolean isSuccessful = true; if (!fileDir.exists()) { isSuccessful = fileDir.mkdir(); } if(!isSuccessful) { return false; } else { File file = new File(PHOTO_PATH); Uri outputFileUri = Uri.fromFile(file); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); activity.startActivityForResult(intent, TAKEPHOTO); return true; } } 
+4
source share
1 answer

Do you have it? You need to override onActivityResult. which will be called before onResume when you use startActivityForResult. The request code will be the code you used to start the taking action. In your case, it will be TAKEPHOTO ..

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKEPHOTO) { if (resultCode == RESULT_OK) { //Pic taken } else { //Pic not taken } } } 

EDIT: take a look at this link http://achorniy.wordpress.com/2010/04/26/howto-launch-android-camera-using-intents/

+2
source

Source: https://habr.com/ru/post/1386827/


All Articles