在Android中重复本地通知

编程入门 行业动态 更新时间:2024-10-27 23:25:54
本文介绍了在Android中重复本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试发出通知,安装了应用程序后,它会在每月的第1个月自动设置警报/通知,并在单击该通知后会打开该应用程序的特定活动

I am trying to make a notification, Whever app is installed, it automatically set alarm/notification every 1st of month and upon clicking that notification it opens a specific activity of the application

这是我的警报管理器代码

Here is my code for alarm manager

// get a Calendar object with current time Calendar cal = Calendar.getInstance(); // add 5 minutes to the calendar object cal.add(Calendar.MINUTE, 5); Intent intent = new Intent(this, AlarmReceiver.class); intent.putExtra(MESSAGE); PendingIntent sender = PendingIntent.getBroadcast(this, 10, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Get the AlarmManager service AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);

我已经设置了警报级别

@Override public void onReceive(Context context, Intent intent) { try { Intent newIntent = new Intent(context, Appointment.class); context.startActivity(newIntent); } catch (Exception e) { Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }

我的问题是,我要将其设置为重复通知,每个月1日。警报代码,我将其保存在mainActivity中。我该如何设置它每月重复一次?

My problem is, i want to set it as a repeating notification, each month on 1st. The alarm code, I have it in my mainActivity. How can i set it that it will repeat each month

推荐答案

安排一个重复警报可以通过setRepeating()of AlarmManager()

public void setRepeating(int类型,长触发器,行长,间隔长,密执业意图)

希望您可以通过检查哪个月份并修改 INTERVAL_DAY * 28 或 INTERVAL_DAY * 30 或 INTERVAL_DAY * 31 通过设置标志和所有其他标志。

Hope you can achieve your goal by checking which month is and modify the INTERVAL_DAY *28 Or INTERVAL_DAY*30 OR INTERVAL_DAY*31 by setting flags and all that.

am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY*30, sender);

更多推荐

在Android中重复本地通知

本文发布于:2023-11-27 02:48:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!