本文整理汇总了Java中android.app.AlarmManager.setWindow方法的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.setWindow方法的具体用法?Java AlarmManager.setWindow怎么用?Java AlarmManager.setWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.AlarmManager
的用法示例。
在下文中一共展示了AlarmManager.setWindow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
private void addAlarm(Context context, GregorianCalendar date) {
int notificationId = new TimelessDate(date).hashCode();
Log.d("ALARM", "Scheduling alarm " + notificationId);
PendingIntent p = PendingIntent.getBroadcast(
context,
notificationId,
new Intent(context, AlarmReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT);
try {
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (manager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
manager.setAlarmClock(new AlarmManager.AlarmClockInfo(date.getTimeInMillis(), p), p);
} else {
manager.setWindow(AlarmManager.RTC_WAKEUP,
date.getTimeInMillis(),
1,
p);
}
serializeAlarm(context, notificationId);
}
} catch (SecurityException e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String errMSG = e.getMessage() + "\n" + sw.toString();
e.printStackTrace();
Activity act = ActivityHelper.getActivity();
if (act != null) {
ErrorDialog.newInstance("ERROR", "Failed to schedule alarm. Did some alarms crash?", errMSG)
.show(act.getFragmentManager(), "ALSECERROR");
}
}
Log.d("ALARM", "Alarm ready for "
+ " " + DateUtilities.GERMAN_STD_STIMEFORMAT.format(date.getTime())
+ DateUtilities.GERMAN_STD_SDATEFORMAT.format(date.getTime()));
}
示例2: setAlarmTime
import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setAlarmTime(Context context, long timeInMillis, Intent intent) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent sender = PendingIntent.getBroadcast(context, intent.getIntExtra("id", 0),
intent, PendingIntent.FLAG_CANCEL_CURRENT);
int interval = (int) intent.getLongExtra("intervalMillis", 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
am.setWindow(AlarmManager.RTC_WAKEUP, timeInMillis, interval, sender);
}
}
示例3: setAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
/**
* @param flag 周期性时间间隔的标志,flag = 0 表示一次性的闹钟, flag = 1 表示每天提醒的闹钟(1天的时间间隔),flag = 2
* 表示按周每周提醒的闹钟(一周的周期性时间间隔)
* @param hour 时
* @param minute 分
* @param id 闹钟的id
* @param week week=0表示一次性闹钟或者按天的周期性闹钟,非0 的情况下是几就代表以周为周期性的周几的闹钟
* @param eventName 闹钟提示事件名字
* @param eventDetail 闹钟提示事件详情
* @param soundOrVibrator 2表示声音和震动都执行,1表示只有铃声提醒,0表示只有震动提醒
*/
public static void setAlarm(Context context, int flag, int hour, int minute, int id, int
week, String eventName, String eventDetail, Date eventDate, int soundOrVibrator) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
long intervalMillis = 0;
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get
(Calendar.DAY_OF_MONTH), hour, minute, 10);
if (flag == 0) {
intervalMillis = 0;
} else if (flag == 1) {
intervalMillis = 24 * 3600 * 1000;
} else if (flag == 2) {
intervalMillis = 24 * 3600 * 1000 * 7;
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(eventDate);
Log.i(TAG, "setAlarm: eventDate"+dateString);
//发送广播
Intent intent = new Intent(ALARM_ACTION);
intent.putExtra("intervalMillis", intervalMillis);
intent.putExtra("eventName", eventName);
intent.putExtra("eventDetail", eventDetail);
intent.putExtra("id", id);
intent.putExtra("eventDate", dateString);
intent.putExtra("soundOrVibrator", soundOrVibrator);
PendingIntent sender = PendingIntent.getBroadcast(context, id, intent, PendingIntent
.FLAG_CANCEL_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
am.setWindow(AlarmManager.RTC_WAKEUP, calMethod(week, calendar.getTimeInMillis()),
intervalMillis, sender);
} else {
if (flag == 0) {
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
} else {
am.setRepeating(AlarmManager.RTC_WAKEUP, calMethod(week, calendar.getTimeInMillis
()), intervalMillis, sender);
}
}
}