【问题标题】:From PendingIntent to Notification从 PendingIntent 到 Notification
【发布时间】:2015-06-22 14:55:14
【问题描述】:

我尝试在每天的给定时间显示一条通知,因此我使用了 AlarmManager,它激活了我的 PendingIntent。现在我试图让这个 PendingIntent 显示一个通知。关于我应该如何完成这项工作的任何想法?

我的代码:

private AlarmManager alarmMgr;
private PendingIntent alarmIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    check_products(7, 0);
    check_products(16, 0);
}

public void check_products(int hour, int minute){
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent);
}

【问题讨论】:

  • 您能否详细说明为什么您当前的代码不起作用?
  • @aochagavia 我根本不知道如何/在哪里定义我的通知...

标签: android android-notifications android-pendingintent


【解决方案1】:

您必须为您的任务制作广播接收器,因为给定的时间满足要求,然后使用 PendingIntent 生成通知...

【讨论】:

  • 我想我有类似的东西,但我不知道如何通过 PendingIntent 定义通知...
  • 你能把你的电子邮件发给我,这样我就可以给你发一个代码来在待定意图中生成通知..
  • 你能不能把它贴在这里,这样对其他用户会有帮助。我可以接受你的回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
  • 1970-01-01
  • 2014-07-28
  • 2015-06-24
  • 1970-01-01
相关资源
最近更新 更多