解决方法
是的,您可以在
Android上收听日期/时间更改.为此,请在Activity中明确注册以下意图过滤器的
BroadcastReceiver:
android.intent.action.ACTION_TIME_TICK
此意图每分钟发送一次.您无法通过清单中声明的组件接收此信息,但只能通过Context.registerReceiver()明确注册它.
您的Receiver(内部)课程:
private final MyDateChangeReceiver mDateReceiver = new MyDateChangeReceiver(); public class MyDateChangeReceiver extends BroadcastReceiver{ @Override public void onReceive(final Context context,Intent intent) { // compare current time and decide if it's 12 AM Log.d("MyDateChangeReceiver","Time changed"); } }
registerReceiver(mDateReceiver,new IntentFilter(Intent.ACTION_TIME_TICK));
unregisterReceiver(mDateReceiver);