本文整理匯總了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));
}