I want to known what is the purpose of the IntentSender
class for our application? How do we use it in our application?
Are there any good examples, apart from The Android Intent Based APIs: Part Seven – IntentSenders And PendingIntents?
I want to known what is the purpose of the IntentSender
class for our application? How do we use it in our application?
Are there any good examples, apart from The Android Intent Based APIs: Part Seven – IntentSenders And PendingIntents?
IntentSender
is kind of a level of abstraction or glue class that allows you to
Receive broadcast when user selects application in chooser.
Example when you use IntentSender
:
Intent intent = new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
.setType("text/plain");
Intent receiver = new Intent(this, BroadcastTest.class)
.putExtra("test", "test");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
Intent chooser = Intent.createChooser(intent, "test", pendingIntent.getIntentSender());
startActivity(chooser);
Start Activity
with IntentSender
instead of Intent
(more in Android docs)
startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)
Like
startActivity(Intent, Bundle)
, but taking aIntentSender
to start.
The official Android developer documentation for IntentSender
clearly states:
Instances of this class can not be made directly, but rather must be created from an existing
PendingIntent
withPendingIntent.getIntentSender()
.
So, you would(should) not see this class being used directly in a code sample or tutorial.
As for a PendingIntent
, it's basically a token that you give to another application which allows that application to use your app's permissions to execute a specific piece of your app's code.
Here's an example of a PendingIntent
used in a class.