diff options
author | ByteHamster <info@bytehamster.com> | 2021-11-14 12:04:03 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-11-14 12:04:36 +0100 |
commit | 4a2f170a3e1886c1459e4e7597363baa23061db8 (patch) | |
tree | 8931164869d14b4f9489b63d2c48be907190f66b /app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java | |
parent | bae923d710365e688614361a8d4de2406328a90b (diff) | |
download | AntennaPod-4a2f170a3e1886c1459e4e7597363baa23061db8.zip |
Fix Permission Denial when sharing files
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java index aa59e4e96..f7c96a93a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.util.Log; import com.google.android.material.snackbar.Snackbar; @@ -103,22 +102,21 @@ public class BugReportActivity extends AppCompatActivity { Runtime.getRuntime().exec(cmd); //share file try { - Intent i = new Intent(Intent.ACTION_SEND); - i.setType("text/*"); + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/*"); String authString = getString(de.danoeh.antennapod.core.R.string.provider_authority); Uri fileUri = FileProvider.getUriForFile(this, authString, filename); - i.putExtra(Intent.EXTRA_STREAM, fileUri); - i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { - PackageManager pm = getPackageManager(); - List<ResolveInfo> resInfos = pm.queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); - for (ResolveInfo resolveInfo : resInfos) { - String packageName = resolveInfo.activityInfo.packageName; - grantUriPermission(packageName, fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); - } - } + intent.putExtra(Intent.EXTRA_STREAM, fileUri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String chooserTitle = getString(de.danoeh.antennapod.core.R.string.share_file_label); - startActivity(Intent.createChooser(i, chooserTitle)); + Intent chooser = Intent.createChooser(intent, chooserTitle); + List<ResolveInfo> resInfos = getPackageManager() + .queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY); + for (ResolveInfo resolveInfo : resInfos) { + String packageName = resolveInfo.activityInfo.packageName; + grantUriPermission(packageName, fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + startActivity(chooser); } catch (Exception e) { e.printStackTrace(); int strResId = R.string.log_file_share_exception; |