After creating a simple app for capturing photos and storing them in the SURVEYASSIST
folder on the SD card, everything was running smoothly on my Redmi 3s prime (Android version Marshmallow 6.0.1). However, upon opening the app on the Redmi Note 5 pro (Oreo 8.1.0) and clicking on the camera button, the app crashes with an error code displayed as shown in the image.
https://i.sstatic.net/fZCjH.jpg
public class MainActivity extends AppCompatActivity {
public static final int CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE = 1777;
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final String Demo_ImagePath ="/storage/emulated/0/SURVEYASSIST/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
String imgcurTime = dateFormat.format(new Date());
String _path = Demo_ImagePath + File.separator + imgcurTime + ".jpg";
File file = new File(_path);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE);
}
});
}
}