List of usage examples for android.app AlarmManager set
public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation)
Schedule an alarm.
From source file:com.jereksel.rommanager.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. switch (item.getItemId()) { case R.id.delete_xml: new Thread() { public void run() { runOnUiThread(new Runnable() { @Override/*from w ww .j a va2 s . c o m*/ public void run() { Dialog = ProgressDialog.show(context, "Downloading/Preparing Data..", "Please wait", true, false); } }); DownloadXML array; array = new DownloadXML(context, true); (array).start(); try { array.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } runOnUiThread(new Runnable() { @Override public void run() { Dialog.dismiss(); Intent mStartActivity = new Intent(context, MainActivity.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); } }); } }.start(); break; case R.id.about_screen: Intent in = new Intent(context, AboutScreen.class); startActivity(in); break; case R.id.changelog_dialog: Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.AppChangelog)); builder.setCancelable(true); AlertDialog dialog = builder.create(); dialog.show(); break; } return mDrawerToggle.onOptionsItemSelected(item); }
From source file:damo.three.ie.prepay.ConnectivityReceiver.java
@Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (sharedPrefs.getBoolean("backgroundupdate", true) && !(sharedPrefs.getString("mobile", "").equals("") && sharedPrefs.getString("password", "").equals(""))) { Log.d(Constants.TAG, "Internet back!! updating usage!"); Intent receiver = new Intent(context, UpdateReceiver.class); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Using different request code to 0 so it won't conflict main repeating alarm. PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 2, receiver, PendingIntent.FLAG_UPDATE_CURRENT); // Keeping efficiency in mind: // http://developer.android.com/reference/android/app/AlarmManager.html#ELAPSED_REALTIME am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), pendingIntent); // Disable receiver after we scheduled an update. disableReceiver(context);/*from w w w.j av a 2 s .c o m*/ } }
From source file:com.example.babycare.fragments.ExampleFragment.java
private void setAlarm(Context context, long second) { Log.i("TAG", "setAlarm()"); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent Intent = new Intent(getActivity(), Temper_Show_Activity.class); PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, Intent, 0); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis(), pIntent); Log.i("TAG", "setAlarm()"); }
From source file:myblog.richard.vewe.launcher3.LauncherApplication.java
public void restart() { if (mIntent != null) { AlarmManager alarmManager; alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 15000, mIntent); System.exit(2);//ww w . j a v a 2 s .c o m } }
From source file:townley.stuart.app.android.trekkinly.AlertClass.java
@Override public void onReceive(final Context context, Intent intent) { NotificationItemClass notificationItemClass = new NotificationItemClass(); DataBaseHelper db = new DataBaseHelper(context); db.getWritableDatabase();/*w w w . ja v a 2 s .co m*/ db.getNotification(notificationItemClass); if (db.notification <= System.currentTimeMillis()) { createNotification(context, "Something is missing!", "Click here for more details!", "Alert"); ComponentName receiver = new ComponentName(context, AlertClass.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); intent = new Intent(context, AlertClass.class); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(PendingIntent.getBroadcast(context.getApplicationContext(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)); } else if (db.notification > System.currentTimeMillis()) { intent = new Intent(context, AlertClass.class); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, db.notification, PendingIntent .getBroadcast(context.getApplicationContext(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)); } }
From source file:felixwiemuth.lincal.NotificationService.java
@Override protected void onHandleIntent(Intent intent) { calendars = Calendars.getInstance(this); Calendar now = Calendar.getInstance(); Calendar nextAlarm = null;/* w w w . j a v a2 s . c o m*/ for (int i = 0; i < calendars.getCalendarCount(); i++) { LinCalConfig config = calendars.getConfigByPos(i); if (config.isNotificationsEnabled()) { // only load calendar if notifications are enabled LinCal cal = calendars.getCalendarByPos(this, i); if (cal != null) { // if the calendar could not be loaded, skip it (this will also skip scheduling of next notifications for this calendar) Calendar nextTime = processCalendar(cal, config, now); if (nextAlarm == null || (nextTime != null && nextTime.before(nextAlarm))) { nextAlarm = nextTime; } } } } calendars.save(this); // Schedule next processing if there are further entries if (nextAlarm != null) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent processIntent = new Intent(this, NotificationService.class); PendingIntent alarmIntent = PendingIntent.getService(this, 0, processIntent, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, nextAlarm.getTimeInMillis(), alarmIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, nextAlarm.getTimeInMillis(), alarmIntent); } } stopSelf(); }
From source file:com.intel.RtcPingDownloadTester.java
private void setAlarm(long millis) { Intent intent = new Intent(ACTION_NAME); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Log.v(TAG, "setAlarm millis = " + millis); if (millis == 0) return;/* w w w. jav a 2s . co m*/ AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pendingIntent); return; }
From source file:com.bhb27.isu.services.BootBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // only run if the app has run before and main has extracted asserts String action = intent.getAction(); boolean run_boot = Tools.getBoolean("run_boot", false, context); boolean rootAccess = Tools.rootAccess(context); if (Intent.ACTION_BOOT_COMPLETED.equals(action) && rootAccess && run_boot) { Log.d(TAG, " Started action " + action + " run_boot " + run_boot); if (Tools.getBoolean("prop_run", false, context) && Tools.getBoolean("apply_props", false, context)) ContextCompat.startForegroundService(context, new Intent(context, PropsService.class)); ContextCompat.startForegroundService(context, new Intent(context, BootService.class)); if (Tools.getBoolean("apply_su", false, context) && Tools.SuVersionBool(Tools.SuVersion(context))) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent serviceIntent = new Intent("com.bhb27.isu.services.SuServiceReceiver.RUN"); serviceIntent.putExtra("RUN", 100); serviceIntent.setClass(context, SuServiceReceiver.class); serviceIntent.setAction("RUN"); PendingIntent pi = PendingIntent.getBroadcast(context, 100, serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Integer.valueOf(Tools.readString("apply_su_delay", "0", context)), pi); }// w w w . jav a 2s . co m } else Log.d(TAG, "Not Started action " + action + " rootAccess " + rootAccess + " run_boot " + run_boot); }
From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java
private void schedule(long after) { Intent intent = new Intent(ctx, Receiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + after, pi); }
From source file:com.ayuget.redface.job.PrivateMessagesService.java
@TargetApi(android.os.Build.VERSION_CODES.KITKAT) @Override/*from w ww . j a v a 2s.com*/ protected void onHandleIntent(Intent intent) { Log.d(LOG_TAG, "Handling intent"); if (!settings.arePrivateMessagesNoticationsEnabled()) { return; } final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(getApplicationContext()); for (User redfaceUser : userManager.getRealUsers()) { subscriptions.add(mdService.getNewPrivateMessages(redfaceUser) .subscribe(new EndlessObserver<List<PrivateMessage>>() { @Override public void onNext(List<PrivateMessage> privateMessages) { for (PrivateMessage privateMessage : privateMessages) { // Prepare intent to deal with clicks Intent resultIntent = new Intent(PrivateMessagesService.this, PrivateMessagesActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); resultIntent.putExtra(UIConstants.ARG_SELECTED_PM, privateMessage); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder( getApplicationContext()).setSmallIcon(R.drawable.ic_action_emo_wonder) .setColor(getResources().getColor(R.color.theme_primary)) .setContentTitle(privateMessage.getRecipient()) .setContentText(privateMessage.getSubject()) .setContentIntent(resultPendingIntent).setAutoCancel(true); builder.setVibrate(VIBRATION_PATTERN); notificationManager.notify((int) privateMessage.getId(), builder.build()); } } })); } // Setup next alarm long wakeUpTime = System.currentTimeMillis() + settings.getPrivateMessagesPollingFrequency() * DateUtils.MINUTE_IN_MILLIS; AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, PrivateMessagesService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Log.d(LOG_TAG, "Going to sleep, setting wake-up alarm to: " + wakeUpTime); if (AndroidUtils.isKitKatOrHigher()) { am.setExact(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } else { am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } }