1

我正在尝试测试文件选择器的可用性。我假设如果没有可用的错误将返回,但是,事实并非如此。

这是我的代码:

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!");
        }
    }

不过,没有异常被发送回我的日常工作。操作系统似乎正在处理错误并生成一个对话框,说明“没有应用程序可以执行此操作”。

知道我在这里做错了什么吗?

谢谢!

4

1 回答 1

0

实际上,在这个帖子中找到了答案:

Android:我可以从 3rd 方应用程序中使用此意图吗?

请参阅响应者发布的“isIntentAvailable”例程。

谢谢大家!

于 2015-01-23T02:53:53.270 回答