Sending a crime report
You include the text of the report and the string for the subject of the report as extras. Note that these
extras use constants defined in the Intent class. Any activity responding to this intent will know these
constants and what to do with the associated values.
Run CriminalIntent and press the SEND CRIME REPORT button. Because this intent will likely
match many activities on the device, you will probably see a list of activities presented in a chooser
(Figure 15.3).
Figure 15.3 Activities volunteering to send your crime report
If you are offered a choice, make a selection. You will see your crime report loaded into the app that
you chose. All you have to do is address and send it.
If, on the other hand, you do not see a chooser, that means one of two things. Either you have already
set a default app for an identical implicit intent, or your device has only a single activity that can
respond to this intent.
Often, it is best to go with the user’s default app for an action. In CriminalIntent, however, you always
want the user to have a choice for ACTION_SEND. Today a user might want to be discreet and email the
crime report, but tomorrow he or she may prefer public shaming via Twitter.
You can create a chooser to be shown every time an implicit intent is used to start an activity. After
you create your implicit intent as before, you call the following Intent method and pass in the implicit
intent and a string for the chooser’s title:
public static Intent createChooser(Intent target, String title)
Then you pass the intent returned from createChooser(...) into startActivity(...).