PhoneGap android app需要获取外部sdcard路径,但它只返回内部sdcard路径

时间:2013-09-20 07:01:25

标签: javascript android cordova

我正在使用phonegap for android应用程序获取外部卡,

我正在使用此代码:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Hello World</title>
        <link rel="stylesheet" href="css/index.css" type="text/css" />
        <script src="js/jquery.js" type="text/javascript"></script>
        <script src="cordova.js" type="text/javascript"></script>
        <script type="text/javascript">
            window.appRootDirName = "app";
            document.addEventListener("deviceready", onDeviceReady, false);

            function onDeviceReady() {
                console.log("device is ready");
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
                alert(window.appRootDir.fullPath);

            }

            function fail() {
                console.log("failed to get filesystem");
            }



            function gotFS(fileSystem) {
                console.log("filesystem got");
                window.fileSystem = fileSystem;
                fileSystem.root.getDirectory(window.appRootDirName, {
                    create: true,
                    exclusive: false
                }, dirReady, fail);
            }

            function dirReady(entry) {
                window.appRootDir = entry;

                console.log("application dir is ready");
            }



        </script>
    </head>
    <body>


    </body>
</html>

返回file://mnt/sdcard/app - 这是我的内部手机存储路径 外部路径为file://mnt/ext_card/app

如何在phonegap中获取外部卡路径?

1 个答案:

答案 0 :(得分:0)

最后我发现我们无法获得外部SD卡路径,

Environment.getExternalStorageState();

仅返回内部SD卡路径

参考: http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()