android在特定时间,在特定时间发送给用户的通知Android

我正在尝试使用报警管理器在特定时间向用户发送通知.基本上,什么也没有发生,对我来说代码看起来不错.我的Alarm Manager的代码如下:

/** Notify the user when they have a task */

public void notifyAtTime() {

Intent myIntent = new Intent(PlanActivity.this,Notification.class);

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

PendingIntent pendingIntent = PendingIntent.getService(PlanActivity.this,myIntent,0);

Calendar calendar = Calendar.getInstance();

calendar.set(Calendar.HOUR_OF_DAY,12);

calendar.set(Calendar.MINUTE,17);

calendar.set(Calendar.SECOND,00);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),24*60*60*1000,pendingIntent);

}

“通知”类中的通知代码如下:

public class Notification extends Service {

@Override

public void onCreate() {

Toast.makeText(this,"Notification",Toast.LENGTH_LONG).show();

Intent intent = new Intent(this,PlanActivity.class);

PendingIntent pending = PendingIntent.getActivity(this,intent,0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(

this).setSmallIcon(R.drawable.ic_launcher)

.setContentTitle("Football")

.setContentText("Don't forget that you have Football planned!")

.setContentIntent(pending);

NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

manager.notify(0,mBuilder.build());

}

@Override

public IBinder onBind(Intent intent) {

// TODO Auto-generated method stub

return null;

}

}

在Notification类中设置的Toast也不会出现.我不知道这是真的很傻,我失踪了,但任何帮助将不胜感激!

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值