I am having an issue when trying to retrieve a photo from the camera
I am trying to allow the user to take a photo with the camera application, then show a preview of it in the application.
I will also need access to the file at a later stage in the application (But this is not an issue)
I am having the following crash:
Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{41f55850 10769:com.sec.android.app.camera/u0a84} (pid=10769, uid=10084) that is not exported from uid 10119
I have followed This link and a couple others. I dont have an issue on devices like my Galaxy S8+. Only this device that is running Android 4.4.4 API 19.
Android Manifest:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="my_images"
path="Android/data/com.example.app/files/Pictures" />
</paths>
PhotoActivity.java
private File setUpPhotoFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
String imageFileName = "IMG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return image;
}
Starting the camera intent when clicking a button:
if (isCameraApplicationAvailable(PhotoActivity.this)) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = null;
try {
f = setUpPhotoFile();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(PhotoActivity.this, BuildConfig.APPLICATION_ID + ".provider", f));
} catch (IOException e) {
// Handle exception
}
List<ResolveInfo> resolvedIntentActivities = getPackageManager().queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
grantUriPermission(packageName, Uri.fromFile(f), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(takePictureIntent, ACTION_TAKE_PHOTO);
}
Handle image when complete:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTION_TAKE_PHOTO && resultCode == Activity.RESULT_OK) {
handleCameraPhoto();
}
}
I dont understand why its only an issue on 4.4.4 and not other OS's.
When there is a crash, it doesn't say my application crashed, it says Camera has stopped working and I can only view the crash when I am viewing the logs with no filter, which means the crash is not in my application?