2011.07.08(4)——— android Intent.createChooser 应用选择器

参考: http://www.iteye.com/topic/690376
http://www.cnblogs.com/wservices/archive/2010/07/07/1772737.html
http://hi.baidu.com/lck0502/blog/item/2d0036efb844a800fcfa3c58.html

也许 下面的场景 我们经常碰到:
2011.07.08(4)——— android Intent.createChooser 应用选择器


但是 你可知道原因 :

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("audio/*");startActivity(Intent.createChooser(intent, "Select music"));


它使用了Intent.ACTION_GET_CONTENT 和 MIME 类型来查找支持audio/* 的所有Data Picker ,允许用户选择其中之一。

我们也可以让自己的activity出现在picker里面 :

<activity android:name=".TestActivity"                  android:label="TestActivity">            <intent-filter><action android:name="android.intent.action.GET_CONTENT" />                 <category android:name="android.intent.category.DEFAULT" />                 <category android:name="android.intent.category.OPENABLE" />                 <data android:mimeType="audio/music1" />            </intent-filter>        </activity>



Intent.ACTION_CHOOSER = “android.intent.action.CHOOSER” 其作用是显示一个Activity选择器。

Intent提供了一个静态的createChooser方法,让我们能够更方便的创建这样一个Intent

我们再看一个设置壁纸的例子
private void startWallpaper() {        closeAllApps(true);        final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);        Intent chooser = Intent.createChooser(pickWallpaper,                getText(R.string.chooser_wallpaper));         startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);    }



在Home界面“按Menu键”--“点击壁纸”后自然就能在一个对话框里列出这些应用,让用户选择到哪里去设置壁纸了,如下图所示。


2011.07.08(4)——— android Intent.createChooser 应用选择器

更多相关文章

  1. 关于android录音权限被用户禁用的问题解决方案
  2. Android设置壁纸的几种方案
  3. Android自动登录 记住用户名密码实现 SharedPreferences
  4. Live Wallpaper动态壁纸开发
  5. Android多用户原理
  6. Android非主用户无线相关设置的显示
  7. Android开发——本地存储、用户权限获取

随机推荐

  1. Android系统启动研究1
  2. Android中播放GIF动画
  3. Android多线程下载远程图片
  4. Android(安卓)Hook 机制 简单实战
  5. Google Docs for Android(安卓)应用改进
  6. 后台应用不应做Android待机电池杀手
  7. Android编译系统入门(一)
  8. Unity导出android工程集成到android stud
  9. 大话企业级android读书笔记(一)
  10. Android(安卓)创建定时任务