mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	Don't use a chooser for other intents than opening a content in a browser or sharing a content to other apps
Use an ACTION_CHOOSER intent has a negative impact for user experience, because user cannot set as default an activity for an intent
This commit is contained in:
		| @@ -129,11 +129,7 @@ public final class CheckForNewAppVersion { | |||||||
|  |  | ||||||
|         if (BuildConfig.VERSION_CODE < versionCode) { |         if (BuildConfig.VERSION_CODE < versionCode) { | ||||||
|             // A pending intent to open the apk location url in the browser. |             // A pending intent to open the apk location url in the browser. | ||||||
|             final Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl)); |             final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl)); | ||||||
|             viewIntent.putExtra(Intent.EXTRA_TITLE, R.string.open_with); |  | ||||||
|  |  | ||||||
|             final Intent intent = new Intent(Intent.ACTION_CHOOSER); |  | ||||||
|             intent.putExtra(Intent.EXTRA_INTENT, viewIntent); |  | ||||||
|             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||||
|             final PendingIntent pendingIntent |             final PendingIntent pendingIntent | ||||||
|                     = PendingIntent.getActivity(application, 0, intent, 0); |                     = PendingIntent.getActivity(application, 0, intent, 0); | ||||||
|   | |||||||
| @@ -19,7 +19,6 @@ import java.util.Objects | |||||||
|  */ |  */ | ||||||
| class LicenseFragment : Fragment() { | class LicenseFragment : Fragment() { | ||||||
|     private lateinit var softwareComponents: Array<SoftwareComponent> |     private lateinit var softwareComponents: Array<SoftwareComponent> | ||||||
|     private var componentForContextMenu: SoftwareComponent? = null |  | ||||||
|     private var activeLicense: License? = null |     private var activeLicense: License? = null | ||||||
|     private val compositeDisposable = CompositeDisposable() |     private val compositeDisposable = CompositeDisposable() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -117,9 +117,8 @@ public final class ShareUtils { | |||||||
|      * The intent can be of every type, excepted a web intent for which |      * The intent can be of every type, excepted a web intent for which | ||||||
|      * {@link #openUrlInBrowser(Context, String, boolean)} should be used. |      * {@link #openUrlInBrowser(Context, String, boolean)} should be used. | ||||||
|      * <p> |      * <p> | ||||||
|      * If no app is set as default, fallbacks to |      * If no app can open the intent, a toast with the message {@code No app on your device can | ||||||
|      * {@link #openAppChooser(Context, Intent, boolean)}. |      * open this} is shown. | ||||||
|      * <p> |  | ||||||
|      * |      * | ||||||
|      * @param context   the context to use |      * @param context   the context to use | ||||||
|      * @param intent    the intent to open |      * @param intent    the intent to open | ||||||
| @@ -132,27 +131,15 @@ public final class ShareUtils { | |||||||
|                                           final boolean showToast) { |                                           final boolean showToast) { | ||||||
|         final String defaultPackageName = getDefaultAppPackageName(context, intent); |         final String defaultPackageName = getDefaultAppPackageName(context, intent); | ||||||
|  |  | ||||||
|         if (defaultPackageName.equals("android")) { |         if (defaultPackageName.isEmpty()) { | ||||||
|             // No app set as default (doesn't work on some devices) |             // No app installed to open the intent | ||||||
|             openAppChooser(context, intent, true); |             if (showToast) { | ||||||
|         } else { |                 Toast.makeText(context, R.string.no_app_to_open_intent, Toast.LENGTH_LONG) | ||||||
|             if (defaultPackageName.isEmpty()) { |                         .show(); | ||||||
|                 // No app installed to open the intent |  | ||||||
|                 if (showToast) { |  | ||||||
|                     Toast.makeText(context, R.string.no_app_to_open_intent, Toast.LENGTH_LONG) |  | ||||||
|                             .show(); |  | ||||||
|                 } |  | ||||||
|                 return false; |  | ||||||
|             } else { |  | ||||||
|                 try { |  | ||||||
|                     intent.setPackage(defaultPackageName); |  | ||||||
|                     context.startActivity(intent); |  | ||||||
|                 } catch (final ActivityNotFoundException e) { |  | ||||||
|                     // Not an app to open the intent but an app chooser because of OEMs changes |  | ||||||
|                     intent.setPackage(null); |  | ||||||
|                     openAppChooser(context, intent, true); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|  |             return false; | ||||||
|  |         } else { | ||||||
|  |             context.startActivity(intent); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
| @@ -256,6 +243,7 @@ public final class ShareUtils { | |||||||
|                                  final String imagePreviewUrl) { |                                  final String imagePreviewUrl) { | ||||||
|         final Intent shareIntent = new Intent(Intent.ACTION_SEND); |         final Intent shareIntent = new Intent(Intent.ACTION_SEND); | ||||||
|         shareIntent.setType("text/plain"); |         shareIntent.setType("text/plain"); | ||||||
|  |         shareIntent.putExtra(Intent.EXTRA_TEXT, content); | ||||||
|         if (!title.isEmpty()) { |         if (!title.isEmpty()) { | ||||||
|             shareIntent.putExtra(Intent.EXTRA_TITLE, title); |             shareIntent.putExtra(Intent.EXTRA_TITLE, title); | ||||||
|         } |         } | ||||||
| @@ -267,7 +255,6 @@ public final class ShareUtils { | |||||||
|         if (!imagePreviewUrl.isEmpty()) { |         if (!imagePreviewUrl.isEmpty()) { | ||||||
|             //shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |             //shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||||||
|         }*/ |         }*/ | ||||||
|         shareIntent.putExtra(Intent.EXTRA_TEXT, content); |  | ||||||
|  |  | ||||||
|         openAppChooser(context, shareIntent, false); |         openAppChooser(context, shareIntent, false); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 TiA4f8R
					TiA4f8R