diff options
author | cketti <ck@cketti.de> | 2022-03-15 20:21:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 20:21:20 +0100 |
commit | a7e795241e09df2d7b8773599185905afa8f54ff (patch) | |
tree | 36f121fd81c78c0710bc5e7979c280c4e7314b4a /app/src/main | |
parent | 197a0a10443fdc189ecababe6805880609204d87 (diff) | |
download | AntennaPod-a7e795241e09df2d7b8773599185905afa8f54ff.zip |
Use ShareCompat.IntentBuilder for all share actions (#5780)
Diffstat (limited to 'app/src/main')
3 files changed, 16 insertions, 42 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0f8242e63..ff6c917dd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -366,11 +366,4 @@ android:resource="@xml/actions" /> </application> - <queries> - <intent> - <action android:name="android.intent.action.SEND" /> - <data android:mimeType="text/*" /> - </intent> - </queries> - </manifest> 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 f7c96a93a..64e5a109c 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/BugReportActivity.java @@ -3,9 +3,6 @@ package de.danoeh.antennapod.activity; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -14,6 +11,7 @@ import com.google.android.material.snackbar.Snackbar; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ShareCompat; import androidx.core.content.FileProvider; @@ -32,7 +30,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.Charset; -import java.util.List; /** * Displays the 'crash report' screen @@ -102,21 +99,14 @@ public class BugReportActivity extends AppCompatActivity { Runtime.getRuntime().exec(cmd); //share file try { - 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); - 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); - 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); + String authority = getString(R.string.provider_authority); + Uri fileUri = FileProvider.getUriForFile(this, authority, filename); + + new ShareCompat.IntentBuilder(this) + .setType("text/*") + .addStream(fileUri) + .setChooserTitle(R.string.share_file_label) + .startChooser(); } catch (Exception e) { e.printStackTrace(); int strResId = R.string.log_file_share_exception; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java index 5bbc8f0a0..378e669b2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java @@ -5,8 +5,6 @@ import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -18,6 +16,7 @@ import androidx.activity.result.contract.ActivityResultContracts.GetContent; import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; +import androidx.core.app.ShareCompat; import androidx.core.content.FileProvider; import androidx.preference.PreferenceFragmentCompat; import com.google.android.material.snackbar.Snackbar; @@ -41,7 +40,6 @@ import io.reactivex.schedulers.Schedulers; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; import java.util.Locale; public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { @@ -201,19 +199,12 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { alert.setTitle(R.string.export_success_title); alert.setMessage(getContext().getString(R.string.export_success_sum, path)); alert.setPositiveButton(R.string.send_label, (dialog, which) -> { - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.opml_export_label)); - sendIntent.putExtra(Intent.EXTRA_STREAM, streamUri); - sendIntent.setType("text/plain"); - sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Intent chooserIntent = Intent.createChooser(sendIntent, getString(R.string.send_label)); - List<ResolveInfo> resInfoList = getContext().getPackageManager() - .queryIntentActivities(sendIntent, PackageManager.MATCH_DEFAULT_ONLY); - for (ResolveInfo resolveInfo : resInfoList) { - String packageName = resolveInfo.activityInfo.packageName; - getContext().grantUriPermission(packageName, streamUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); - } - getContext().startActivity(chooserIntent); + new ShareCompat.IntentBuilder(getContext()) + .setType("text/*") + .setSubject(getString(R.string.opml_export_label)) + .addStream(streamUri) + .setChooserTitle(R.string.send_label) + .startChooser(); }); alert.create().show(); } |