尝试在Cordova中启动Intent时出现ActivityNotFoundException [英] ActivityNotFoundException when attempting to launch Intent in Cordova

查看:190
本文介绍了尝试在Cordova中启动Intent时出现ActivityNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I create an activity/intent in the android manifest to fix the error below...

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

I am using https://github.com/MaginSoft/MFileChooser and I can see the picker and the file in the browser but I get 'android.content.ActivityNotFoundException' error

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代码.

here is the java code from the plugin..

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

感谢您的帮助

推荐答案

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

The error is telling you that the device has no applications installed that are able to handle that particular implicit intent. You need to check whether an application is available before attempting to launch the intent like this:

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

这篇关于尝试在Cordova中启动Intent时出现ActivityNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆