Grant uri permissions manually to support lower api levels.
Fixes:
@@ -14,6 +14,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.database.Cursor;
import android.database.MatrixCursor;
@@ -801,8 +802,6 @@ public class ZulipActivity extends BaseActivity implements
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
- Log.i("photo captured", mCurrentPhotoPath);
-
// send file path to PhotoSendActivity
Intent photoSendIntent = new Intent(this, PhotoSendActivity.class);
photoSendIntent.putExtra(Intent.EXTRA_TEXT, mCurrentPhotoPath);
@@ -883,6 +882,14 @@ public class ZulipActivity extends BaseActivity implements
"com.zulip.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoURI);
+
+ // grant uri permissions for lower api levels
+ List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);
+ for (ResolveInfo resolveInfo : resInfoList) {
+ String packageName = resolveInfo.activityInfo.packageName;
+ this.grantUriPermission(packageName, mPhotoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ }
+
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
