尝试在Cordova中启动Intent时的ActivityNotFoundException

时间:2016-10-13 19:50:34

标签: android cordova cordova-plugins

如何在Android清单中创建活动/意图以修复以下错误...

我正在使用https://github.com/MaginSoft/MFileChooser,我可以在浏览器中看到选择器和文件,但我得到了' android.content.ActivityNotFoundException'错误

W/No activity found to handle file chooser intent.:
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.GET_CONTENT cat=
android.intent.category.OPENABLE] typ=.doc,.docx,.rdf,.txt,.pdf,.odt }

这是来自插件的java代码..

public void chooseFile(CallbackContext callbackContext) {

        // type and title should be configurable
        Context context=this.cordova.getActivity().getApplicationContext();
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setClass(context,FileChooserActivity.class);

        Intent chooser = Intent.createChooser(intent, "Select File");
        cordova.startActivityForResult(this, chooser, PICK_FILE_REQUEST);

        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callback = callbackContext;
        callbackContext.sendPluginResult(pluginResult);
}

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

错误告诉您设备没有安装能够处理特定隐式意图的应用程序。在尝试启动这样的意图之前,您需要检查应用程序是否可用:

// Verify that there are applications registered to handle this intent
// resolveActivity returns null if none are registered
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}