My camera code is working in all Android versions but in Nougat 7.0 it gives the following error:
java.lang.NullPointerException: Attempt to invoke virtual meth
Do this on click of camera button or camera image click event
Uri fileUri;
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
ContentValues values = new ContentValues(1);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg");
fileUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
Log.d("FILEURI",fileUri+"");
editor.putString("Fileurl", fileUri+"");
editor.commit();
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
Do this in onActivityResult method
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
try {
String utlstr =preferences.getString("Fileurl","");
Log.d("sad",utlstr);
Uri uri = Uri.parse(utlstr);
final File file = inputStreamToFile(getContentResolver().openInputStream(uri), "png");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}