Android的通知在特定的日期 [英] Android notification at specific date
问题描述
我必须做的一个应用程序在至极我必须设置一个日期,并在9点钟位置的具体日期我必须这样做的通知。什么是最简单的这样做的方法是什么?(我想该应用,如果我重新启动我的电话,或者拿出我的电池工作,即使是AlarmManager一个解决方案吗?)
I have to do an app in wich i must set a date and at that specific date at 9 o'clock i must do a notification. What is the simplest method of doing that?(i want the app to work even if i reboot my phone, or take out my battery, is AlarmManager a solution?)
推荐答案
要正点,你可以使用AlarmeManager一个动作
To schedul an Action you can use the AlarmeManager
试试这个code这是为我工作:
Try this code it's work for me:
1 /声明BoradcastReceiver类启动操作,这个类可以在你的活动或境外在其他的java文件
1 / Declare the BoradcastReceiver CLASS to launch the Action, this class can be inside your activity or outside in an other java file
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, intent.getStringExtra("param"),Toast.LENGTH_SHORT).show();
}
}
2 /在你的onCreate方法把这个code
2/ Inside your Oncreate Method put this code
AlarmManager alarms = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
Receiver receiver = new Receiver();
IntentFilter filter = new IntentFilter("ALARM_ACTION");
registerReceiver(receiver, filter);
Intent intent = new Intent("ALARM_ACTION");
intent.putExtra("param", "My scheduled action");
PendingIntent operation = PendingIntent.getBroadcast(this, 0, intent, 0);
// I choose 3s after the launch of my application
alarms.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3000, operation) ;
启动应用程序举杯将出现在3秒后,所以,你可以改变System.currentTimeMillis的()+ 3000你醒来的时间。
Launch your App a Toast will be appeared after 3 seconds, So you can change "System.currentTimeMillis()+3000" with your wake up time.
这篇关于Android的通知在特定的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!