如何在Ionic 1中设置意图类型以仅选择png和pdf文件

时间:2018-08-03 09:59:05

标签: android cordova ionic-framework

我正在使用自定义文件选择器插件来选择工作正常的文件。我想在打开文件选择器时仅获取png和pdf文件。但是当我将类型设置为在插件中仅提供png和pdf文件时不起作用。

插件代码:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(type);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);

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

使用插件:

customFileChooser.open({"image/png, application/pdf"}, function (uri) {
    $log.log('success uri is', uri);
  }, function (error) {
    $log.log('error is', error);
  });

我也想知道如何将所选文件转换为base64

插件链接:click to view the plugin

0 个答案:

没有答案