Browse Source

Fixed viewing attachments

main
M66B 6 years ago
parent
commit
87ebf47a83
3 changed files with 11 additions and 6 deletions
  1. +1
    -1
      app/src/main/AndroidManifest.xml
  2. +9
    -4
      app/src/main/java/eu/faircode/email/AdapterAttachment.java
  3. +1
    -1
      app/src/main/res/xml/fileprovider_paths.xml

+ 1
- 1
app/src/main/AndroidManifest.xml View File

@ -60,7 +60,7 @@
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="eu.faircode.email"
android:authorities="${applicationId}"
android:exported="false"
android:grantUriPermissions="true">
<meta-data


+ 9
- 4
app/src/main/java/eu/faircode/email/AdapterAttachment.java View File

@ -185,19 +185,24 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
File file = new File(dir, attachment.filename);
// https://developer.android.com/reference/android/support/v4/content/FileProvider
Uri uri = FileProvider.getUriForFile(context, "eu.faircode.email", file);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
Log.i(Helper.TAG, "uri=" + uri);
// Build intent
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setType(attachment.type);
intent.setDataAndType(uri, attachment.type);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Log.i(Helper.TAG, "Sharing " + file + " type=" + attachment.type);
Log.i(Helper.TAG, "Intent=" + intent);
//context.startActivity(Intent.createChooser(intent, attachment.name));
// Set permissions
List<ResolveInfo> targets = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : targets)
for (ResolveInfo resolveInfo : targets) {
Log.i(Helper.TAG, "Target=" + resolveInfo);
context.grantUriPermission(resolveInfo.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
// Check if viewer available
if (targets.size() == 0) {


+ 1
- 1
app/src/main/res/xml/fileprovider_paths.xml View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="attachments"
path="attachments" />


Loading…
Cancel
Save