Android常用功能实例 如IMEI号
2010-07-15 20:14:00 来源:WEB开发网}
}
public static class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "闹钟提示:时间到!", Toast.LENGTH_LONG).show();
}
}
2、建立Intent和PendingIntent,来调用目标组件。
Java代码
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
3、设置闹钟
获取闹钟管理的实例:
Java代码
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
设置单次闹钟:
Java代码
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5*1000), pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5*1000), pendingIntent);
设置周期闹钟:
Java代码
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10*1000), (24*60*60*1000), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10*1000), (24*60*60*1000), pendingIntent);
搞定!当然这里闹钟的响应处理只是用的文字,你可以播放声音,或都用更复杂的一系统通知,在这里你就是上帝,一切由你做主。
更多精彩
赞助商链接