Browse Source

Fixed no viewer message

main
M66B 6 years ago
parent
commit
28d93cf785
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      app/src/main/java/eu/faircode/email/AdapterAttachment.java

+ 17
- 10
app/src/main/java/eu/faircode/email/AdapterAttachment.java View File

@ -98,15 +98,26 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
} }
}); });
} else { } else {
// Build file name
File dir = new File(context.getCacheDir(), "attachments");
dir.mkdir();
final File file = new File(dir, TextUtils.isEmpty(attachment.name) ? "noname" : attachment.name);
// Check if viewer available
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.fromFile(file));
PackageManager pm = context.getPackageManager();
if (pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) == null) {
Toast.makeText(context, R.string.title_no_viewer, Toast.LENGTH_LONG).show();
return;
}
// View // View
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
// Build file name
File dir = new File(context.getCacheDir(), "attachments");
dir.mkdir();
File file = new File(dir, TextUtils.isEmpty(attachment.name) ? "" : attachment.name);
// Create file
if (!file.exists()) { if (!file.exists()) {
file.createNewFile(); file.createNewFile();
@ -135,12 +146,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
for (ResolveInfo resolveInfo : targets) for (ResolveInfo resolveInfo : targets)
context.grantUriPermission(resolveInfo.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); context.grantUriPermission(resolveInfo.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
// Start view
Log.i(Helper.TAG, "Targets=" + targets.size());
if (targets.size() > 0)
context.startActivity(intent);
else
Toast.makeText(context, R.string.title_no_viewer, Toast.LENGTH_LONG).show();
// Start viewer
context.startActivity(intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.i(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.i(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
} }


Loading…
Cancel
Save