ActivityNotFoundException when attempting to launch Intent in Cordova

ぃ、小莉子 提交于 2019-12-02 10:51:19

问题


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

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 }

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

Thanks for your help


回答1:


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


来源:https://stackoverflow.com/questions/40029732/activitynotfoundexception-when-attempting-to-launch-intent-in-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!