首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Cordova FileTransfer插件在Android 5+上不起作用

Cordova FileTransfer插件在Android 5+上不起作用
EN

Stack Overflow用户
提问于 2017-05-30 10:21:50
回答 1查看 1.1K关注 0票数 1

我正在用PhoneGap构建一个应用程序,只针对安卓系统。其中一项功能是将文件从web服务器下载到设备。

这段代码在Android 4.x上运行得很好,但在Android 5.x和更高版本上就不能运行:

代码语言:javascript
运行
AI代码解释
复制
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) {
	var download_link = encodeURI(URL);

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

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

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

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

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

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

不要在控制台中得到任何东西,没有错误,也没有日志行,这意味着没有任何回调被触发。

还有其他人有这个神秘的问题吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-06-25 07:49:25

尝试安装这些版本。

代码语言:javascript
运行
AI代码解释
复制
phonegap plugin remove cordova-plugin-file
phonegap plugin remove cordova-plugin-file-transfer

phonegap plugin add cordova-plugin-file@4.3.3
phonegap plugin add cordova-plugin-file-transfer@1.5.1

我正在使用这些版本,我在Anrdoid 5,6,7中没有问题,试试吧。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44259585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档