mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 15:32:52 +00:00
Prevent crash
This commit is contained in:
parent
7aea1370ca
commit
26496c1341
4 changed files with 43 additions and 22 deletions
|
@ -205,17 +205,27 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|||
if (attachment == null || !attachment.available)
|
||||
return false;
|
||||
|
||||
File file = attachment.getFile(context);
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
try {
|
||||
File file = attachment.getFile(context);
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
|
||||
Intent send = new Intent();
|
||||
send.setAction(Intent.ACTION_SEND);
|
||||
send.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
send.setType(attachment.getMimeType());
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
context.startActivity(Intent.createChooser(send, context.getString(R.string.title_select_app)));
|
||||
Intent send = new Intent();
|
||||
send.setAction(Intent.ACTION_SEND);
|
||||
send.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
send.setType(attachment.getMimeType());
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
context.startActivity(Intent.createChooser(send, context.getString(R.string.title_select_app)));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
/*
|
||||
java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(SourceFile:730)
|
||||
at androidx.core.content.FileProvider.getUriForFile(SourceFile:418)
|
||||
*/
|
||||
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void onDelete(final EntityAttachment attachment) {
|
||||
|
|
|
@ -4775,22 +4775,21 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
if (message.raw == null || !message.raw) {
|
||||
properties.setValue("raw_send", message.id, true);
|
||||
rawDownload(message);
|
||||
} else {
|
||||
File file = message.getRawFile(context);
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
|
||||
Intent send = new Intent(Intent.ACTION_SEND);
|
||||
send.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
send.setType("message/rfc822");
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
} else
|
||||
try {
|
||||
File file = message.getRawFile(context);
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
|
||||
Intent send = new Intent(Intent.ACTION_SEND);
|
||||
send.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
send.setType("message/rfc822");
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
context.startActivity(send);
|
||||
} catch (ActivityNotFoundException ex) {
|
||||
Log.w(ex);
|
||||
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, send), Toast.LENGTH_LONG).show();
|
||||
} catch (Throwable ex) {
|
||||
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void rawDownload(TupleMessageEx message) {
|
||||
|
|
|
@ -2164,6 +2164,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
Log.w(ex);
|
||||
Snackbar.make(view, getString(R.string.title_no_viewer, intent), Snackbar.LENGTH_LONG)
|
||||
.setGestureInsetBottomIgnored(true).show();
|
||||
} catch (Throwable ex) {
|
||||
// / java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -483,6 +483,15 @@ public class Helper {
|
|||
}
|
||||
|
||||
static void share(Context context, File file, String type, String name) {
|
||||
try {
|
||||
_share(context, file, type, name);
|
||||
} catch (Throwable ex) {
|
||||
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void _share(Context context, File file, String type, String name) {
|
||||
// https://developer.android.com/reference/android/support/v4/content/FileProvider
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
Log.i("uri=" + uri);
|
||||
|
|
Loading…
Reference in a new issue