java - 当设备处于 sleep 模式时,如何在 Android 中的某个特定时间推送本地通知

标签 java android android-studio push-notification notifications

实际上我正在尝试制作我的大学日常应用程序..它使用NotificationManager向用户通知当前周期(我总共有九个周期,有些处于不同的时间间隔)...它一切正常,但是当设备进入休眠状态时出现问题,它不会在 sleep 模式下推送任何通知...我正在使用服务来推送通知,但我猜服务也会在 sleep 模式下进入休眠状态...我的服务在 sleep 期间永远不会自动终止...但它不会发出任何通知...请帮助我

Click Here to view my code

最佳答案

我使用广播接收器执行此操作,我设置每 60 秒重复一次广播

像这样:

Intent notificationIntent = new Intent(context,thebroadcastclass.class);
        notificationIntent.addCategory("android.intent.category.HIGH");
        broadcast = PendingIntent.getBroadcast(context.getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),60000, broadcast);

它工作正常,但间隔必须至少 60 秒 (这会耗尽电池太多)

这是广播接收器:

public class thebroadcastclass extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        toastmaker.update(context, intent);
    }}

我希望你能使用这个(:

关于java - 当设备处于 sleep 模式时,如何在 Android 中的某个特定时间推送本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015678/

相关文章:

java - 从起始 ip 和广播 ip 确定子网/cidr

Java 将 ids 数组添加到 SQL Server 的准备语句中

java - ActionListener 将变量的当前值重置为默认值

java - 如何解决 Android Studio 中的重新声明错误

java - 将 Spring Security 与 SiteMinder 集成

android - Android 中类似 Twitter 的闪屏动画

android - 在 Android 上对文件系统进行分区

android - 前缀 'context' 不能在此处使用,因为它被本地声明所遮蔽

android - 如何检测电话何时被接听或拒绝

android - android google maps中两点之间的距离/时间