Skip to content

Commit

Permalink
Request edit with canonical file
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Nov 18, 2023
1 parent bc1edac commit 92159e4
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1924,15 +1924,24 @@ public void onReceive(Context context, Intent intent) {
*
* @param file File that should be edited
*/
public void requestFileEdit(final Context context, final File file) {
final Uri uri = FileProvider.getUriForFile(context, getFileProvider(context), file);
final Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setDataAndType(uri, GsFileUtils.getMimeType(file));
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(EXTRA_FILEPATH, file.getAbsolutePath());
startActivity(context, intent);
public void requestFileEdit(final Context context, File file) {
if (file == null || !file.exists()) {
return;
}

try {
file = file.getCanonicalFile();
final Uri uri = FileProvider.getUriForFile(context, getFileProvider(context), file);
final Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setDataAndType(uri, GsFileUtils.getMimeType(file));
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(EXTRA_FILEPATH, file.getPath());
startActivity(context, intent);
} catch (IOException e) {
Log.e(GsContextUtils.class.getName(), "ERROR: Failed to get canonical file path");
}
}

/**
Expand Down

0 comments on commit 92159e4

Please sign in to comment.