其他分享
首页 > 其他分享> > 尝试在Cordova中启动Intent时出现android-ActivityNotFoundException

尝试在Cordova中启动Intent时出现android-ActivityNotFoundException

作者:互联网

如何在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);
}

谢谢你的帮助

解决方法:

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

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

标签:android,cordova,cordova-plugins
来源: https://codeday.me/bug/20191012/1903560.html