Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Phonegap下载文件并保存在内部存储器中_Android_Cordova_Ionic - Fatal编程技术网

Android Phonegap下载文件并保存在内部存储器中

Android Phonegap下载文件并保存在内部存储器中,android,cordova,ionic,Android,Cordova,Ionic,我正在尝试从服务器下载文件,然后使用phonegap将其保存到设备的内部存储器。这是我到目前为止所拥有的 if(ionic.Platform.isAndroid()){ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){ fileSystem.root.getFile("test.mp3", { create: true, exclusive: false

我正在尝试从服务器下载文件,然后使用phonegap将其保存到设备的内部存储器。这是我到目前为止所拥有的

if(ionic.Platform.isAndroid()){
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
    fileSystem.root.getFile("test.mp3", {
      create: true,
      exclusive: false
    }, function(fileEntry){
      var sPath = fileEntry.fullPath; // equals /test.mp3
      // sPath = "file:///storage/sdcard0/test.mp3";
      var fileTransfer = new FileTransfer();
      fileEntry.remove();
      fileTransfer.download(
        ringtone.streamUrl,
        sPath,
        function(theFile){
          alert(theFile);
        }
        );
    });
  }, null);
}

问题是当我给出下载的绝对文件路径时,比如
file:///storage/sdcard0/test.mp3
它可以将文件完美地下载到内部存储器中,但如果使用sPath变量则无法工作。据我所知,我无法获得内部存储目录的绝对路径。如何使用phonegap在android中获取
文件中的内部存储路径://
格式。

我不确定这是标准的还是推荐的方法,但我已经在LG G2、Samasung Galaxy S3和2部Motorolla手机上进行了测试,效果非常好。 我只是使用下面的命令连接到模拟器

adb shell
进入

ls -la
结果,在根
/
目录中有一个名为sdcard的目录,它是指向位于其他地方的原始sdcard文件夹的符号链接

ls -la

sdcard -> storage/sdcard0

因此路径
file:///sdcard/test.mp3
为我做了这件事。

如果没有sd卡,我想在内存中保存图像。我的问题是