code: private static void grantUriPermissionsForIntent(final Activity context, final Uri outputDestination, final Intent intent) {
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
              final List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
              for (ResolveInfo resolveInfo : resInfoList) {
                  final String packageName = resolveInfo.activityInfo.packageName;
                  context.grantUriPermission(packageName, outputDestination, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
              }
          }
      }
docs: Grant permissions to read/write the given URI.
  Take from: http://stackoverflow.com/a/33754937/1234900