android - 使用 native URL 的 ionic 删除文件

标签 android cordova ionic-framework

我正在使用 CSDK image编辑器来编辑图像。这是编辑图像的方法:-

CSDKImageEditor.edit(success, error, imageUrl, options);

因此,成功后,方法编辑器将返回图像 url,其格式如下:-

content://media/23

我需要在编辑后删除该文件。所以我正在使用 Cordova File删除文件。由于这是 native url,因此 cordova 文件无法找到使用该 url 的文件。通过谷歌后我得到了一个插件 Corodva Filepath将 native url 转换为文件 url,但是这个插件不起作用。安装插件后,我无法构建文件。

所以问题是,我需要删除文件,但我没有文件 url,我只有 native url。请给我一些建议,以便我可以使用 native url 删除文件,或者我可以将 native Url 转换为 Ionic1 中的文件 url

最佳答案

混合应用程序无法直接访问文件系统。这就是您不能使用 content://media/23 的原因。

您可以使用 cordova-plugin-file by Apache访问文件和this Post如何删除它:

var path = "file:///storage/emulated/0";
var filename = "myfile.txt";

window.resolveLocalFileSystemURL(path, function(dir) {
    dir.getFile(filename, {create:false}, function(fileEntry) {
              fileEntry.remove(function(){
                  // The file has been removed succesfully
              },function(error){
                  // Error deleting the file
              },function(){
                 // The file doesn't exist
              });
    });
}); 

关于android - 使用 native URL 的 ionic 删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47069764/

相关文章:

android - 方向重置 Activity Android

java - 无法启动 Activity - ComponentInfo 错误

css - 我怎样才能在标签中始终保留两位小数并对齐价目表

ionic-framework - 将 Controller 传递给 $ionicModal

javascript - IONIC - 构造函数中的 BluetoothSerial 使所有元素不可见

安卓底部导航 View : too much space between icon and text

android - 从对话框 fragment 启动 Activity

java - 如何在 Android java 代码中同时使用 CordovaActivity 和 AppCompatActivity?

ios - HTML 嵌入式 Vimeo 播放器在 Cordova CLI 5.4.1 和 6.2.0 中失败

android - Cordova 找不到 Theme.AppCompat.Light