Improved share error handling

This commit is contained in:
M66B 2022-11-02 18:45:14 +01:00
parent 2a4b220b7b
commit 2b7b1c83b8
3 changed files with 13 additions and 9 deletions

View File

@ -349,8 +349,12 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
}
private void onShare(EntityAttachment attachment) {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);
try {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);
} catch (Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}
private void onDownload(EntityAttachment attachment) {

View File

@ -210,7 +210,11 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
EntityAttachment attachment = items.get(pos);
if (attachment.available)
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), attachment.name);
try {
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), attachment.name);
} catch (Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
else {
if (attachment.progress == null) {
Bundle args = new Bundle();

View File

@ -866,12 +866,8 @@ public class Helper {
static void share(Context context, File file, String type, String name) {
// https://developer.android.com/reference/androidx/core/content/FileProvider
try {
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
share(context, uri, type, name);
} catch (Throwable ex) {
Log.e(ex);
}
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
share(context, uri, type, name);
}
static void share(Context context, Uri uri, String type, String name) {