3

Phonegap2.2.0を使用してEclipseでAndroidアプリを構築しています

これはiOSで機能しました:

var uri = encodeURI(value);
var fileName = uri.substring(uri.lastIndexOf('/')+1);

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
        fileSystem.root.getDirectory("dir/subdir", {create: true, exclusive: false}, function(dirEntry){
            dirEntry.getFile(fileName, {create: true, exclusive: false}, function(fileEntry) {
                var localPath = fileEntry.fullPath;
                var fileTransfer = new FileTransfer();
                fileTransfer.download(
                    uri,
                    localPath,
                    function(entry) {
                        console.log("xfg download complete: " + entry.fullPath);
                    },
                    function(error) {
                        console.log("xfg download error source " + error.source);
                        console.log("xfg download error target " + error.target);
                        console.log("xfg upload error code" + error.code);
                    }
                );

            });
        });
    });

上記のコードの4行目で、「dir / subdir」のディレクトリを取得しており、ダウンロードは正常に機能します。ただし、Androidでは、fileSystemはサブディレクトリを取得しますが、ダウンロードは「ファイルが見つかりません」で失敗します。

「dir/subdir」を「dir」に置き換えると機能します。

これに対する解決策または巧妙な回避策はありますか?

4

2 に答える 2

2

navigatorオブジェクトのuserAgentプロパティを調べることで、デバイスの種類を特定できます。

if((navigator.userAgent.match(/Android/i)) == "Android")

Android デバイスの場合は、dir代わりに を使用しdir/subdirます。

参照: phonegap でのデバイス タイプの検出

于 2012-11-20T00:31:29.593 に答える
1

ディレクトリがすでに存在しない限り、サブディレクトリを指定することはできません。だから作成しgetDirectory('dir'...ますgetDirectory('subdir'...

https://developer.mozilla.org/en-US/docs/DOM/File_API/File_System_API/DirectoryEntry

DirectoryEntryから検索または作成するディレクトリへの絶対パスまたは相対パス。直接の親がまだ存在しないファイルを作成しようとするとエラーになります。

于 2012-11-20T01:50:38.023 に答える