报错提示:
保存到公共下载目录失败:targetSdkVersion设置>=29后在Android10 系统设备不支持当前路径。请更改为应用运行路径!
plus.io.resolveLocalFileSystemURL(
filePath,
function (entry) {
const cachePath = plus.io.convertLocalFileSystemURL("_cache");
//安卓10+上无法保存到指定文件
console.log("_cache", entry.name, cachePath);
entry.copyTo(
cachePath,
entry.name,
function (newEntry) {
console.log("文件已保存到公共下载目录:" + newEntry.fullPath);
},
function (e) {
console.log("保存到公共下载目录失败:" + e.message);
}
);
},
function (e) {
console.log("解析文件路径失败:" + e.message);
}
);
外壳运行在自定义基座上,对了一下 cachePath 路里的包名没问题。但是还是报错了,为什么还是不能拷贝啊
为什么都使用的是私有应用路径了还是不行啊?应用运行路径是?
1 个回复
h***@qq.com
下面是测试成功的App.vue源码,包含了拷贝文件的功能,供参考:
<script>
export default {
onLaunch: async function() {
try {
await this.copyDatabase(); // 当doc目录下不存在数据库时,使用已有的库文件
} catch (e) {
console.log('Error: ', e)
}
},
onShow: function() {},
onHide: function() {},
methods: {
async copyDatabase() {
// 仅 Android/iOS 执行
// #ifdef APP-PLUS
const dbName = 'mira';
</script>
<style>
/每个页面公共css /
</style>