@@ -17,6 +17,7 @@ next.link=result.html
1717 <li><a href="#Build">Build an Implicit Intent</a></li>
1818 <li><a href="#Verify">Verify There is an App to Receive the Intent</a></li>
1919 <li><a href="#StartActivity">Start an Activity with the Intent</a></li>
20+ <li><a href="#AppChooser">Show an App Chooser</a></li>
2021</ol>
2122
2223<h2>You should also read</h2>
@@ -208,4 +209,45 @@ if (isIntentSafe) {
208209
209210
210211
212+ <h2 id="AppChooser">Show an App Chooser</h2>
213+
214+ <div class="figure" style="width:200px">
215+ <img src="{@docRoot}images/training/basics/intent-chooser.png" alt="" />
216+ <p class="img-caption"><strong>Figure 2.</strong> Example of the chooser dialog that appears
217+ when you use {@link android.content.Intent#createChooser createChooser()} to ensure
218+ that the user is always shown a list of apps that respond to your intent.</p>
219+ </div>
220+
221+ <p>Notice that when you start an activity by passing your {@link android.content.Intent} to {@link
222+ android.app.Activity#startActivity startActivity()} and there is more than one app that responds to
223+ the intent, the user can select which app to use by default (by selecting a checkbox at the bottom
224+ of the dialog; see figure 1). This is nice when performing an action for which the user
225+ generally wants to use the same app every time, such as when opening a web page (users
226+ likely use just one web browser) or taking a photo (users likely prefer one camera). However, if
227+ the action to be performed could be handled by multiple apps and the user might
228+ prefer a different app each time—such as a "share" action, for which users might have several
229+ apps through which they might share an item—you should explicitly show a chooser dialog,
230+ which forces the user to select which app to use for the action every time (the user cannot select a
231+ default app for the action).</p>
232+
233+ <p>To show the chooser, create an {@link android.content.Intent} using {@link
234+ android.content.Intent#createChooser createChooser()} and pass it to {@link
235+ android.app.Activity#startActivity startActivity()}. For example:</p>
236+
237+ <pre>
238+ Intent intent = new Intent(Intent.ACTION_SEND);
239+ ...
240+
241+ // Always use string resources for UI text. This says something like "Share this photo with"
242+ String title = getResources().getText(R.string.chooser_title);
243+ // Create and start the chooser
244+ Intent chooser = Intent.createChooser(intent, title);
245+ startActivity(chooser);
246+ </pre>
247+
248+ <p>This displays a dialog with a list of apps that respond to the intent passed to the {@link
249+ android.content.Intent#createChooser createChooser()} method and uses the supplied text as the
250+ dialog title.</p>
251+
252+
211253
0 commit comments