这是我的用例:
单击按钮时,我希望将JSON字符串保存在文件中并启动本地通知。当我点击此通知时,我想打开我的文件(之前创建的)以在默认应用程序中显示他的内容。
问题:
我的函数正在运行以将JSON字符串保存在文件中并启动通知(我可以手动查看文件中的字符串)。但是,当我点击通知时,应用程序打开默认应用程序,但文件为空。
这是我单击按钮时启动的代码(我也下载了一张图片,但这部分运行正常):
downloadReceipt(): void {
// Listener when I click on the notification
this.notif.on("click", (notif) => {
let type = notif.id == 1 ? "text/*" : "image/png";
this.FileOpener.open(notif.data, type).then((file) => console.log("File opened : ", file)).catch((err) => console.error("Error openening : ", err));
});
const fileTransfer: TransferObject = this.transfer.create();
// Ask to get the anchor
this.dbApi.getAnchorId(this.parameters.path).then((message) => {
console.log("Get anchor ID : ", message);
// Get the content of the anchor
this.woleetApi.getReceipt(message['id']).then((message) => {
let dataStr = JSON.stringify(message['content']);
// Check if the anchor is ready
if (message['content']['extra'] == undefined){
this.dialogs.alert("The receipt is not yet ready")
} else {
// Create and save the file
this.file.createFile(this.file.externalDataDirectory, 'receipt.json', true).then((msg) => {
this.file.writeExistingFile(this.file.externalDataDirectory, 'receipt.json', dataStr).then((msg) => {
// Launch the notification for the receipt
this.notif.schedule({
id: 1,
text: 'Receipt downloaded',
title: 'Download receipt',
data: this.file.externalDataDirectory + 'receipt.json'
});
}).catch((err) => {
console.error("writeExistingFile error :", err);
})
}).catch((err) => {
console.error("CreateFile error :", err);
})
// Download the picture
fileTransfer.download(this.parameters.picture, this.file.externalDataDirectory + 'picture.png').then((entry) => {
console.log("Download complete: " + entry.toURL());
// Launch the notification for the picture
this.notif.schedule({
id: 2,
text: 'Image downloaded',
title: 'Download picture',
data: this.file.externalDataDirectory + 'picture.png'
})
}).catch((err) => console.error("Error during download", err));
}
})
})
}
我在Android设备上运行此代码。
任何人都可以帮助我?
谢谢