gpt4 book ai didi

android - 如何在Android中设置可靠的长期警报?

转载 作者:搜寻专家 更新时间:2023-11-01 07:55:21 25 4
gpt4 key购买 nike

我正在使用 Phonegap 开发 Android 应用程序。我需要设置一个长期闹钟来提醒用户一些事情,比如每月的任务。

我正在为此搜索插件,但我发现最流行的插件没有足够的可靠性。我试过使用它,但它只适用于短期警报,而且并不总是有效。

我问了开发者,他说他不知道为什么会失败。

在这种情况下,我打算开发自己的插件来帮助我解决这个问题。

我对 Android 原生有中等经验,但我之前有一个问题:

¿在Android上设置这种高可靠性的长期警报的方法是什么,最好是没有服务,并且是最简单的方法? ¿这可能吗?

当然,我想保留警报,即使手机重启,应用程序被杀死等等。

PD:谢谢,对不起我的英语水平。

最佳答案

我不知道,你测试的是哪个插件,因为你没有提到它。

Katzer 的这个插件是您安排提醒所需要的: https://github.com/katzer/cordova-plugin-local-notifications/

这是计划的本地通知的示例:

window.plugin.notification.local.add({
id: String, // A unique id of the notification
date: Date, // This expects a date object
message: String, // The message that is displayed
title: String, // The title of the message
repeat: String, // Either 'secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'
badge: Number, // Displays number badge to notification
sound: String, // A sound to be played
json: String, // Data to be passed through the notification
autoCancel: Boolean, // Setting this flag and the notification is automatically cancelled when the user clicks it
ongoing: Boolean, // Prevent clearing of notification (Android only)
}, callback, scope);

这就是您如何为将来的某个日期安排通知的方式:

var now                  = new Date().getTime(),
_60_seconds_from_now = new Date(now + 60*1000);

window.plugin.notification.local.add({
id: 1,
title: 'Reminder',
message: 'Dont forget to buy some flowers.',
repeat: 'weekly',
date: _60_seconds_from_now
});

实际时间可以用这个脚本计算:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

today = mm+'/'+dd+'/'+yyyy;
document.write(today);

这应该对你有帮助。

关于android - 如何在Android中设置可靠的长期警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28516403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com