How to Know Which Intent Is Selected in Intent.Action_Send

How to tell which app was selected by Intent.createChooser?

On Android 5.1+, you can use the three-parameter edition of the createChooser() method, where the last parameter is an IntentSender that you can use to find out what was chosen.

Prior to Android 5.1, there is nothing in Android to let you know what the user chose.

How to know which intent is selected in Intent.ACTION_SEND?

You can't get such information.

Unless you create your own implementation of the dialog for the activity selection.

To create such dialog you need to use PackageManager and its queryIntentActivities() function. The function returns List<ResolveInfo>.

ResolveInfo contains some information about an activity (resolveInfo.activityInfo.packageName), and with the help of PackageManager you can get other information (useful for displaying the activity in the dialog) - application icon drawable, application label, ... .

Display the results in a list in a dialog (or in an activity styled as a dialog). When an item is clicked create new Intent.ACTION_SEND, add the content you want and add the package of the selected activity (intent.setPackage(pkgName)).

Is it possible to detect if an ACTION_SEND Intent suceeded?

Is there a way to read an intent response?

Not from an arbitrary activity for an arbitrary action.

The documentation for Intent actions will tell you if there is expected output or not. So, for example, ACTION_GET_CONTENT is documented to have output. For those Intent actions, you use startActivityForResult(), and part of the output will be a "result code" to let you know generally what the result was.

However:

  • Not every Intent action is documented to have output. Notably, ACTION_SEND is not documented to have output. In that case, you don't use startActivityForResult() (but instead use startActivity()). Even if you do use startActivityForResult(), you have no way to know if a negative outcome means that the user cancelled out or if the other activity simply is following the documentation and did not return a result.

  • Some activities are buggy and fail to return results when they should.

  • Your definition of a successful result and the activity's definition of a successful result may differ.

How to know which application the user chose when using an intent chooser?

As far as I know, there is no direct way to gather such information. What would you need it for? Imho the android intent system was designed so you, as an app developer, don't have to worry about what app the user chose to handle your intent.

How can I detect if user selected from createChooser options?

From Android's source, you can see that the Activity that chooses among Intents doesn't setResult() at all. That should be requested as a feature.



Related Topics



Leave a reply



Submit