我正在尝试测试文件选择器的可用性。我假设如果没有可用的错误将返回,但是,事实并非如此。
这是我的代码:
public void doImport() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Select a File to Import"), IMPORT_RACES_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Utils.Error(this, "THERE WAS NO NAVIGATOR FOUND, Install a navigator!");
} catch (Exception e) {
Utils.Error(this, "Some other error occurred!");
}
}
不过,没有异常被发送回我的日常工作。操作系统似乎正在处理错误并生成一个对话框,说明“没有应用程序可以执行此操作”。
知道我在这里做错了什么吗?
谢谢!