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 的有两个:
转载于:https://www.cnblogs.com/dongdong230/p/4317768.html