本文整理汇总了Java中android.app.AlarmManager.set方法的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.set方法的具体用法?Java AlarmManager.set怎么用?Java AlarmManager.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.AlarmManager
的用法示例。
在下文中一共展示了AlarmManager.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Calendar calendar = Calendar.getInstance();
if (calendar.get(Calendar.HOUR_OF_DAY) > 7) {
calendar.add(Calendar.DATE, 1);
calendar.set(Calendar.HOUR_OF_DAY, 7);
} else {
calendar.set(Calendar.HOUR_OF_DAY, 7);
}
Intent receiver_intent = new Intent(context,
ActivityCheckReceiver.class);
receiver_intent.putExtra("action",
"com.taipeitech.action.ACTIVITY_CHECK");
PendingIntent pi = PendingIntent.getBroadcast(context, 1,
receiver_intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);
}
示例2: setNotification
import android.app.AlarmManager; //导入方法依赖的package包/类
private void setNotification(long time) {
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("whut.dongdong.easynote.NOTIFY_BROADCAST");
intent.putExtra("noteId", noteId);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(this, noteId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
manager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else {
manager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
}
ToastUtil.showToast(this, "提醒设置成功");
}
示例3: onStartCommand
import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
boolean isUpdateTime = pref.getBoolean("isUpdateTime", true);
if (isUpdateTime == true){
updateWeather();
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
int autoUpdateTime = pref.getInt("autoUpdateTime", 60);
int anHour = autoUpdateTime * 60 * 1000; // 这是 60 分钟的毫秒数
long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
Intent i = new Intent(this, AutoUpdateService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
manager.cancel(pi);
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
}
return super.onStartCommand(intent, flags, startId);
}
示例4: restartApplication
import android.app.AlarmManager; //导入方法依赖的package包/类
/**
* 重启App
*
* @param context application
* @param delay 当前App被杀死之后,延迟多久重新启动。
*/
public static void restartApplication(Context context, int delay) {
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(context.getPackageName());
PendingIntent restartIntent = PendingIntent.getActivity(context.getApplicationContext(), 0
, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
int type = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long triggerTime = SystemClock.elapsedRealtime() + delay;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mgr.setExact(type, triggerTime, restartIntent);
} else {
mgr.set(type, triggerTime, restartIntent);
}
Process.killProcess(Process.myPid());
}
示例5: ScheduleNotification
import android.app.AlarmManager; //导入方法依赖的package包/类
public void ScheduleNotification(Notification notification,
Context context, int notificationID, String dateTime) {
Intent notificationIntent = new Intent(context, NotificationPublisher.class);
notificationIntent.putExtra(NOTIFICATION_ID, notificationID);
notificationIntent.putExtra(NOTIFICATION, notification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// parse string parameter to milliseconds for later alarm set
Date futureInMillis = null;
try {
futureInMillis = dateTimeFormatter.parse(dateTime);
} catch (ParseException e) {
e.printStackTrace();
}
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, futureInMillis.getTime(), pendingIntent);
}
示例6: onCreate
import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intentAlarm = new Intent(this, BroadcastAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//Set the alarm to wake up the device and set the time interval
//and set the broadcast receiver for this alarm
alarmManager.set(AlarmManager.RTC_WAKEUP, TIME_INTERVAL, pendingIntent);
}
示例7: restartActivity
import android.app.AlarmManager; //导入方法依赖的package包/类
public static void restartActivity(Context context, Class<?> clz) {
Intent intent = new Intent(context, clz);
PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//退出程序
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 300,
restartIntent); // 1秒钟后重启应用
android.os.Process.killProcess(android.os.Process.myPid());
}
示例8: startRTCWakeUpAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
public static void startRTCWakeUpAlarm(Context context, Class<?> cls, LocalDateTime date)
{
// 获取AlarmManager系统服务
Calendar c=getCalendar(date);
Intent intent = new Intent(context, cls);
intent.putExtra("date",date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));//向receiver发送还是用intent
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
//设置一个PendingIntent对象,发送广播
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);
}
示例9: setExactAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
/**
* Wrapper to set alarm at exact time
* @see AlarmManager#setExact(int, long, PendingIntent)
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void setExactAlarm(AlarmManager alarmManager, int alarmType, long firstTime,
PendingIntent pendingIntent) {
if(isCompatible(Build.VERSION_CODES.KITKAT)) {
alarmManager.setExact(alarmType, firstTime, pendingIntent);
}else {
alarmManager.set(alarmType, firstTime, pendingIntent);
}
}
示例10: restart
import android.app.AlarmManager; //导入方法依赖的package包/类
public static void restart(Context context, int delay) {
if (delay == 0) {
delay = 1;
}
Intent restartIntent = context.getPackageManager()
.getLaunchIntentForPackage(context.getPackageName() );
restartIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
PendingIntent intent = PendingIntent.getActivity(
context, 0,
restartIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC, java.lang.System.currentTimeMillis() + delay, intent);
java.lang.System.exit(2);
}
示例11: onStartCommand
import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
updateWeather();
updateBingPic();
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
int anHour = 8 * 60 * 60 * 1000; // 这是8小时的毫秒数
long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
Intent i = new Intent(this, AutoUpdateService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
manager.cancel(pi);
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
return super.onStartCommand(intent, flags, startId);
}
示例12: startAlarmClock
import android.app.AlarmManager; //导入方法依赖的package包/类
@TargetApi(19)
public static void startAlarmClock(Context context, AlarmModel alarm) {
Intent intent = new Intent(context, BootAlarmActivity.class);
intent.putExtra(ALARM_CLOCK, alarm);
PendingIntent pi = PendingIntent.getActivity(context, alarm.id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long nextTime = calculateNextTime(alarm.hour,
alarm.minute, getWeeks(alarm));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, nextTime, pi);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, nextTime, pi);
}
}
示例13: setalarm
import android.app.AlarmManager; //导入方法依赖的package包/类
public void setalarm() {
if ((!database.isOpen()) || database == null) {
database = openOrCreateDatabase("db.db", MODE_PRIVATE, null);// 打开数据库
}
int requestCode = 0;
// ------------------------------
String table = "list";
String[] columns = { "content", "alarm", "flag", "dataid" };
String selection = null;
String[] selectionArgs = null;
Cursor cursor = database.query(table, columns, selection,
selectionArgs, null, null, null);
cursor.moveToPosition(cursor.getCount() - 1);// 移动到最后一行
int idColumnIndex = cursor.getColumnIndex("dataid");
int idValue = cursor.getInt(idColumnIndex); // 得到最后一行的id
int contentColumnIndex = cursor.getColumnIndex("content");
String contentValue = cursor.getString(contentColumnIndex); // 得到最后一行的内容
int alarmColumnIndex = cursor.getColumnIndex("alarm");
String alarmValue = cursor.getString(alarmColumnIndex); // 得到最后一行的闹铃时间
requestCode = idValue;
// ---------------------------------------------------------------------
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(List.this, ClockActivity.class);
intent.putExtra("content", contentValue);// 传递内容
intent.putExtra("alarmtime", alarmValue);// 传递闹铃时间
pi = PendingIntent.getActivity(List.this, requestCode, intent,
PendingIntent.FLAG_CANCEL_CURRENT); // 根据id设置不同的闹钟
Calendar alarmTime = Calendar.getInstance();
long alarmdatetime = changedatetime(alarmValue); // 将时间转换为long型
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmdatetime, pi);
Toast.makeText(getApplicationContext(), "闹钟设置好了", Toast.LENGTH_LONG)
.show();
database.close();// 关闭数据库连接
}
示例14: a
import android.app.AlarmManager; //导入方法依赖的package包/类
public synchronized void a(Intent intent, long j) {
if (this.a == null) {
AlarmManager alarmManager = (AlarmManager) this.b.getSystemService("alarm");
this.a = PendingIntent.getBroadcast(this.b, 0, intent, 0);
if (VERSION.SDK_INT >= 19) {
a(alarmManager, j, this.a);
} else {
alarmManager.set(0, j, this.a);
}
b.c("register timer " + c);
}
}
示例15: setUpdateAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
private void setUpdateAlarm() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.add(Calendar.MINUTE, 1);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)
alarmManager.setExact(AlarmManager.RTC, calendar.getTimeInMillis(), createClockUpdateIntent(this));
else
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), createClockUpdateIntent(this));
}