0

I read this answer from @CommonsWare.


This happens when I open the devices default camera application. But it doesn't happen on my Samsung J7 Pro running 8.1.0

I open the camera like this:

Uri videoUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", filePlusName);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.setPackage(defaultCameraPackageName);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(intent, VIDEO_REQUEST_CODE);//Crash pointing to this

I'm not sure if doing it like this will solve the issue (I doubt it)?

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.setPackage(defaultCameraPackageName);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName() + ".provider", filePlusName));
startActivityForResult(intent, VIDEO_REQUEST_CODE);//Crash pointing to this

I have no idea why this is happening,

Any advise would greatly be appreciated .

ClassA
  • 2,480
  • 1
  • 26
  • 57
  • Get rid of `intent.setPackage(defaultCameraPackageName)`. – CommonsWare Jun 21 '19 at 15:38
  • @CommonsWare I got that from this answer, I tried detecting the default camera - https://stackoverflow.com/a/9064049/8199772 – ClassA Jun 21 '19 at 15:40
  • That answer is awful. Please remove `intent.setPackage(defaultCameraPackageName)`, and allow the user to choose which camera app to use (if they happen to have more than one installed). – CommonsWare Jun 21 '19 at 15:56
  • @CommonsWare Ok I will do, thank you. – ClassA Jun 21 '19 at 15:57
  • @CommansWare I would just like to let you know that removing that resolved my issue. Thank you. I guess there is no way to select the device's default camera app. – ClassA Jun 22 '19 at 03:12

0 Answers0