if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(android.Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Allow access to the camera and try again", Toast.LENGTH_SHORT).show();
requestPermissions(new String[]{Manifest.permission.CAMERA}, 0);
return true;
}
}
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
try {
File sharePath = new File(getCacheDir(), "share");
if (sharePath.mkdir()) {
Toast.makeText(this, "share dir created", Toast.LENGTH_SHORT).show();
}
photoFile = File.createTempFile(
"photo", /* prefix */
".png", /* suffix */
sharePath /* directory */
);
} catch (IOException ex) {
// Error occurred while creating the File
App.showToast("Error");
}
// Continue only if the File was successfully created
if (photoFile != null) {
String dop="PRO";
String ver = BuildConfig.VERSION_NAME;
if(!ver.endsWith("-pro")) {
dop="FREE";
}
Uri photoURI = FileProvider.getUriForFile(this,
"ru.a402d.paperang.fileprovider"+dop,
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, CAMERA_SELECT_CODE);
}
}else{
Toast.makeText(this, getString(R.string.need_camera), Toast.LENGTH_LONG).show();
}