【问题标题】:Ionic Cordova file plugin premission deniedIonic Cordova 文件插件权限被拒绝
【发布时间】:2016-06-27 12:54:53
【问题描述】:

我遇到了这个问题:我的应用程序(Android 版本)下载 PDF 文件并将它们保存到 cordova.file.dataDirectory。然后,用户可以通过本机应用程序(如 adobe reader 和 gmail)打开或发送 PDF 文件。这是我的问题...当我想将 pdf 附加到 gmail 或在 adobe 应用程序中打开 pdf 时,我收到消息(它在屏幕上弹出)gmail(或 acrobat)无权打开我的 pdf。在cordova 文件插件的文档中,该数据目录在“私有”下。但只有其他非私人文件夹在 SD 卡上,但不是每部手机都有这张卡,所以这不是解决方案。有没有办法解决这个问题?我可以创建对文件夹没有限制权限的文件夹并将我的 pdf-s 保存在 thah 文件夹中吗?

我大约在 1 年前制作了这个应用程序,现在我想做一些更新,但现在我遇到了权限问题(我的旧版本没有这些权限。用户可以查看和发送他们想要的文件,无论如何他们使用的是什么 Android 操作系统)。

任何帮助将不胜感激。

【问题讨论】:

    标签: android cordova pdf permissions ionic-framework


    【解决方案1】:

    使用cordova-plugin-file 创建目录。

    使用以下代码在设备中创建新目录。 如果给定的代码正确执行,那么它将在文件系统的根目录下创建一个目录。

    window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
      var entry = fileSystem.root;
      entry.getDirectory("Directory_Name", { // Give your directory name instead of Directory_Name
        create: true,
        exclusive: false
      },onSuccess, onFail);
    },null);
    
    // onSuccess function for creating directory
     function onSuccess(parent) {
       dirPath = parent.nativeURL; // It will return location of the folder in device
       console.log(dirPath);
     }
    
    // onFail function for creating directory
    function onFail(error) {
      console.log(error);
    }
    

    Follow SO referred link.

    【讨论】:

    • 此文件夹和所有内容是否可供其他应用使用?非常感谢您的重播,将尽快检查此代码并相应地标记您的答案。
    猜你喜欢
    • 2011-11-10
    • 2012-11-24
    • 2013-02-27
    • 2017-06-28
    • 2017-12-25
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多