Reputation: 1016
I have an existing market place version of the app working fine with all other android versions. But recently I noticed that the image upload features of my application (through both gallery and camera) doesn't work on my phone (recently upgraded to Nougat). On debugging i noticed that the code breaks in the below point
ExifInterface exif = new ExifInterface(uriImage.toString());
Although uriImage seems to have a valid url. (value I confirmed this by doing new File(uriImage.toString()) and it seems to be working fine. The value of uriImage.toString() at this point is..
I had search the internet for this and found no results. Although i suspect the Nougat behaviour explained in the link below. I have made the changes suggested by the author, but the issue persists. Below is my code for triggering the camera/picker intents
public static Uri startChooseImage(Activity parent, String tag, String message, boolean useCamera, int requestId)
{
Uri uriImage = FileProvider.getUriForFile(parent,
"com.dyt.fileprovider",
new File(
Environment.getExternalStorageDirectory() + File.separator + tag));
/* Uri uriImage = Uri.fromFile(new File(
Environment.getExternalStorageDirectory() + File.separator + tag));*/
Intent selIntent = new Intent("android.intent.action.PICK").setType("image/*");
selIntent.setFlags(FLAG_GRANT_READ_URI_PERMISSION);
selIntent.setFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
Intent chooserIntent = Intent.createChooser(selIntent, message);
if (useCamera) {
List<Intent> intentsList = new ArrayList();
Intent camIntent = new Intent("android.media.action.IMAGE_CAPTURE");
camIntent.setFlags(FLAG_GRANT_READ_URI_PERMISSION);
camIntent.setFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
PackageManager pm = parent.getPackageManager();
List<ResolveInfo> listCam = pm.queryIntentActivities(camIntent, 0);
for (ResolveInfo res : listCam) {
Intent finalIntent = new Intent(camIntent);
finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
finalIntent.putExtra("output", uriImage);
intentsList.add(finalIntent);
}
chooserIntent.putExtra("android.intent.extra.INITIAL_INTENTS",
(Parcelable[])intentsList.toArray(new Parcelable[intentsList.size()]));
}
parent.startActivityForResult(chooserIntent, requestId);
return uriImage;
}
Can someone help me on this please?
Upvotes: 0
Views: 1097
Reputation: 11
// add in app manifest file
<provider
android:authorities="com.package.name"
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:readPermission="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/image_path">
</meta-data>
</provider>
// image path define in new xml file
<?xml version="1.0" encoding="utf-8"?>
<external-path
name="images"
path="Android/data/Apppackagename/files/Pictures"/>
Upvotes: 1