• 【起航计划 021】2015 起航计划 Android APIDemo的魔鬼步伐 20 App->Intents createChooser


    Intents 这个例子的代码非常简单:

        public void onGetMusic(View view) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("audio/*");
            startActivity(Intent.createChooser(intent, "Select music"));
        }
    
        public void onGetImage(View view) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivity(Intent.createChooser(intent, "Select image"));
        }
    
        public void onGetStream(View view) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("*/*");
            startActivity(Intent.createChooser(intent, "Select stream"));
        }

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

    比如对于Email应用,允许用户选择某种数据文件作为附件。

    方法createChooser 提供了创建一个ACTION_CHOOSER Intent的便捷方法。

    下图是在模拟器上运行的结果,支持Audio/* MIME 的有两个:

  • 相关阅读:
    习惯
    mysql
    mysql
    mysql
    MYSQL
    MYSQL
    mysql
    手动从Spring中获取指定对象
    jdbc连接数据库
    java代码调用exe(cmd命令)
  • 原文地址:https://www.cnblogs.com/dongdong230/p/4317768.html
Copyright © 2020-2023  润新知