Help me please. Previously, the methods for uploading photos from the gallery and photos worked, but according to the Google condition, they set Target SDK 26. Tekr on Android 7 these methods do not work.

private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File Toast.makeText(this, "Error creating image", Toast.LENGTH_SHORT); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } } } private void dispatchChoosePhotoIntent(){ Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.action_choosePhoto)), REQUEST_SELECT_PHOTO); } static final int REQUEST_IMAGE_CAPTURE = 1; static final int REQUEST_SELECT_PHOTO = 2; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch(requestCode){ case REQUEST_IMAGE_CAPTURE: if(resultCode == RESULT_OK) pictureTaken(); break; case REQUEST_SELECT_PHOTO: if(resultCode == RESULT_OK){ Uri uri = data.getData(); String filePath = Utils.getPath(this, uri); photoFile = new File(filePath); pictureTaken(); } break; default: super.onActivityResult(requestCode, resultCode, data); break; } } private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(null); return File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); } 
  • The easiest way to find a bug is with Lint. It should highlight your mistakes in red or highlight yellow and green from the situation, and you will get a hint when you hover. - Valeriy

0