2017-05-30 4 views
1

に取り組んでいません。機能の1つは、Webサーバーからデバイスにファイルをダウンロードすることです。コルドバ変数をFileTransferプラグインは、私が唯一のAndroidをターゲットに、ビルドするのPhoneGapでアプリケーションを構築していますアンドロイド5+

このコードは、Android 4.xの上で完璧に動作しますが、上記のAndroid 5.xとでは動作しません:なし

var URL = 'https://example.com/path/to/file.pdf?auth_token=123xxxx'; 
 
var Folder_Name = 'Download'; 
 
var File_Name = URL.split('/'); 
 
File_Name = File_Name[File_Name.length - 1].split('?'); 
 
File_Name = File_Name[0]; 
 

 
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemFail); 
 

 
function fileSystemSuccess(fileSystem) { 
 
\t var download_link = encodeURI(URL); 
 

 
\t var directoryEntry = fileSystem.root; // to get root path of directory 
 
\t directoryEntry.getDirectory(Folder_Name, { 
 
\t \t create: true, 
 
\t \t exclusive: false 
 
\t }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard 
 
\t var rootdir = fileSystem.root; 
 
\t var fp = rootdir.toURL(); // Returns Fullpath of local directory 
 

 
\t fp = fp + "/" + Folder_Name + "/" + File_Name; // fullpath and name of the file which we want to give 
 
\t console.log("Path to local file: " + fp); 
 
\t // download function call 
 
\t filetransfer(download_link, fp); 
 
} 
 

 
function onDirectorySuccess(parent) { 
 
\t console.log('directory created successfully'); 
 
\t // Directory created successfuly 
 
} 
 

 
function onDirectoryFail(error) { 
 
\t //Error while creating directory 
 
\t console.log("Unable to create new directory: " + error.code); 
 
} 
 

 
function fileSystemFail(evt) { 
 
\t //Unable to access file system 
 
\t console.log(evt.target.error.code); 
 
} 
 

 
function filetransfer(download_link, fp) { 
 
\t var fileTransfer = new FileTransfer(); 
 
\t // File download function with URL and local path 
 
\t fileTransfer.download(download_link, fp, 
 
\t \t function(entry) { 
 
\t \t \t alert('The file was successfully downloaded, you can access it in /' + Folder_Name + '/' + File_Name + '.'); 
 
\t \t \t console.log("download complete: " + entry.fullPath); 
 
\t \t }, 
 
\t \t function(error) { 
 
\t \t \t //Download abort errors or download failed errors 
 
\t \t \t console.log("download error source " + error.source); 
 
\t \t \t console.log("download error target " + error.target); 
 
\t \t \t console.log("download error code" + error.code); 
 
\t \t } 
 
\t); 
 
}

コンソールには何も取得しないでください、エラーとログ行はなく、コールバックがトリガーされないことを意味します。

誰がこの神秘的な問題はありましたか?

ありがとうございました

+0

ファイル転送プラグインの最新バージョンを持っていますか?私は彼らが許可問題を修正したと思う – Akis

+0

config.xmlにを追加しました。 –

答えて

0

これらのバージョンをインストールしてみてください。

phonegap plugin remove cordova-plugin-file 
phonegap plugin remove cordova-plugin-file-transfer 

phonegap plugin add [email protected] 
phonegap plugin add [email protected] 

私はこれらのバージョンを使用しており、Anrdoid 5,6,7では問題が発生しません。試してみてください。

関連する問題