I am developing an app that in it user share some sound file
You have not described how you are doing this. For this answer, I am going to guess that you are referring to ACTION_SEND
or ACTION_SENDTO
, as those are the typical Intent
actions used for "share" sorts of operations.
If this guess is incorrect, please edit your question to provide the actual Java code that you are using to "share some sound file".
i want to know when user cancel sharing of sounds
There is no way for you to know what the user did, or did not do, with the content that you share via ACTION_SEND
or ACTION_SENDTO
.
If you are implementing your own ContentProvider
for serving the sound file, you can know whether another app has requested that content. However, that still does not imply that the user actually completed some action with that content. For example, if the other app is an email client, it might have read the content to create an email attachment for its compose window, but then the user elected not to send the email.
User can cancel this by pressing back button
Pressing the BACK button does not necessarily imply that the user did not share the content.
Based on your comments, I think you are asking a different question: how do you know if the user chose something from the activity chooser that may appear when you try to share something?
On Android 5.1 and higher, you can use the three-parameter createChooser()
method to arrange to find out what the user chose through the standard system chooser dialog. Prior to that, the only way that I know of to know what the user chose is to not use the system chooser dialog, but to handle that yourself. You can create your own "chooser", to choose among the available options given to you by queryIntentActivities()
on PackageManager
.