Forcing an app chooser

  When there is more than one app that responds to your implicit intent, the user can select which app to use and make that app the default choice for the action. This is nice when performing an action for which the user probably wants to use the same app from now on, such as when opening a web page (users often prefer just one web browser) .

  However, if multiple apps can respond to the intent and the user might want to use a different app each time, you should explicitly show a chooser dialog. The chooser dialog asks the user to select which app to use for the action every time (the user cannot select a default app for the action). For example, when your app performs "share" with the ACTION_SEND action, users may want to share using a different app depending on their current situation, so you should always use the chooser dialog, as shown in figure 2.
              

              Figure 2. A chooser dialog.
  To show the chooser, create an Intent using createChooser() and pass it to startActivity(). For example:

 Intent sendIntent = new Intent(Intent.ACTION_SEND);
... // Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title); // Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

  This displays a dialog with a list of apps that respond to the intent passed to the createChooser() method and uses the supplied text as the dialog title.

Intent官方教程(4)用Intent构造应用选择框的更多相关文章

  1. Intent官方教程(6)常见Intent示例,启动日历,时钟,镜头等。

    guide/components/intents-common.html 包含:Alarm Clock Calendar Camera Contacts/People App Email File S ...

  2. Intent官方教程(3)各属性介绍

    Building an Intent An Intent object carries information that the Android system uses to determine wh ...

  3. Intent官方教程(2)Intent的两种类型

    Intent Types There are two types of intents: Explicit intents specify the component to start by name ...

  4. Intent官方教程(5)在manifest中给组件添加<Intent-filter>

    Receiving an Implicit Intent To advertise which implicit intents your app can receive, declare one o ...

  5. Intent官方教程(1)简介和作用

    Intents An Intent is a messaging object you can use to request an action from another app component. ...

  6. ContentProvider官方教程(7)3种访问形式:批处理、异步访问、intent间接访问(临时URI权限)

    Alternative Forms of Provider Access Three alternative forms of provider access are important in app ...

  7. DroidParts 中文系列教程(基于官方教程)

    DroidParts中文系列教程(基于官方教程) (一)DroidParts框架概况 2014年4月18日星期五 11:36 他是一个精心构造的安卓框架,包括下面这些基本功能 DI依赖注入,可以注入V ...

  8. Android官方教程翻译(4)——启动另一个Activity

    Starting Another Activity 启动另一个Activity PREVIOUSNEXT THIS LESSON TEACHES YOU TO 这节课教你 1.   Respond t ...

  9. Ceisum官方教程2 -- 项目实例(workshop)

    原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...

随机推荐

  1. 有趣的linux命令

    安装工具 debian => apt-get (In Debian like OS) red hat=> yum -y (In Red Hat like OS) mac => bre ...

  2. js同步访问后台资源

    $.ajax( {  type : 'post',  url : url,  data : data,  async : false,//false代表只有在等待ajax执行完毕后才执行window. ...

  3. 4. 星际争霸之php设计模式--工厂方法模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  4. yii2多语言

    1.页面视图(我放在了布局文件main.php中): <a href="javascript:;" onclick="changeLanguage('zh-CN') ...

  5. RAID、软RAID和硬RAID

    RAID(redundant array of inexpensive disks):独立的硬盘冗余阵列,基本思想是把多个小硬盘组合在一起成为一个磁盘组,通过软件或硬件的管理达到性能提升或容量增大或增 ...

  6. 蒙地卡罗法求 PI

    问题: 蒙地卡罗为摩洛哥王国之首都,该国位于法国与义大利国境,以赌博闻名.蒙地卡罗的基本原理为以乱数配合面积公式来进行解题,这种以机率来解题的方式带有赌博的意味,虽然在精确度上有所疑虑,但其解题的思考 ...

  7. OpenStack 物理资源问题

    Contents [hide] 1 写在前面 2 openstack的自有设置 3 解决办法 4 最终解决办法 写在前面 物理CPU核数为12,能虚拟多少虚拟核的机器?openstack的默认使用no ...

  8. linux-kernel 学习计划

    [资料] http://www.ibm.com/developerworks/cn/views/linux/libraryview.jsp http://www.kerneltravel.net/ [ ...

  9. 所谓完整的linux系统包括哪些部分呢?【转】

    本文转载自:http://www.eeskill.com/article/index/id/1358.html 简介:三部分:bootloader.linux kernel(linux内核).root ...

  10. scala偏函数

    package com.ming.test /** * 在Scala中,偏函数是具有类型PartialFunction[-T,+V]的一种函数.T是其接受的函数类型,V是其返回的结果类型. * 偏函数 ...