Cordova + Android:如何获得SD卡的路径?

时间:2015-04-18 14:57:37

标签: android cordova filesystems sd-card android-sdcard

我正在尝试使用Cordova从SD卡播放一些mp3文件(从远程服务器下载的应用程序)。

我尝试使用以下内容:

 if($ionicPlatform.is('android')){
                  src = 'yourPersistantAppFolder/main_expansion/' + src;
                }

 if($ionicPlatform.is('android')){
                  src = 'sdcard/yourPersistantAppFolder/main_expansion/' + src;
                }

但没有运气。

我试图在这里找到一些anwser: https://github.com/apache/cordova-plugin-file

但没有运气。

非常感谢您的任何建议。

修改

Android中的路径显示如下:

enter image description here

1 个答案:

答案 0 :(得分:0)

这可能会有所帮助: (jc ???是mysupport例程)

import { File } from "@ionic-native/file";
import { Diagnostic } from "@ionic-native/diagnostic";

constructor(
    ...
    public file: File,
    public diagnostic: Diagnostic
){

this.diagnostic.getExternalSdCardDetails()
.then( (data) => {
  this.jcError += "\n" + "sd:" + JSON.stringify( data);
  this.jcError += "\n" + "Number cards: " + data.length;
  for( let ii = 0; ii < data.length; ii += 1){
    let thisElem = data[ii];
    if( thisElem.type.toLowerCase() === "application" && thisElem.canWrite){
      this.ourSDentry = thisElem;
      basePathSD = thisElem.filePath;
      break;
    }
  }
  if( !basePathSD){
    this.jcError += "\n\n" + "no SD card found";
    return;
  }
}, (errData)=>{
  tag = "getExternalSdCardDetails";
  this.jcError += "\n\n" + tag + ":ERR:" + JSON.stringify( errData);
});