List of usage examples for android.app AlarmManager RTC
int RTC
To view the source code for android.app AlarmManager RTC.
Click Source Link
From source file:net.gsantner.opoc.util.ContextUtils.java
/** * Restart the current app. Supply the class to start on startup *//*w w w .jav a 2 s . c om*/ public void restartApp(Class classToStart) { Intent inte = new Intent(_context, classToStart); PendingIntent inteP = PendingIntent.getActivity(_context, 555, inte, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) _context.getSystemService(Context.ALARM_SERVICE); if (_context instanceof Activity) { ((Activity) _context).finish(); } if (mgr != null) { mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, inteP); } else { inte.addFlags(FLAG_ACTIVITY_NEW_TASK); _context.startActivity(inte); } Runtime.getRuntime().exit(0); }
From source file:com.dogar.geodesic.map.MainActivity.java
private void restartApp() { Intent mStartActivity = new Intent(this, MainActivity.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0);//from w w w . j av a2s .c o m }
From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java
/** * Set alarm/* w ww. j a v a 2 s. c o m*/ * * @param updateRate * in minutes */ private void setAlarm(long updateRate) { // Set alarm final PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, WeatherNotificationService.class), PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Set time to next hour plus 5 minutes: final long now = System.currentTimeMillis(); long triggerAtTime = now; // set back to last hour plus 2 minutes: triggerAtTime -= triggerAtTime % 3600000 - 12000; // Add selected update rate triggerAtTime += updateRate * 60000; // Check that trigger time is not passed. if (triggerAtTime < now) triggerAtTime = now + updateRate * 60000; alarm.set(AlarmManager.RTC, triggerAtTime, pendingIntent); }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
/** * Start an alarm that fires on the next quarter hour to update the world clock city * day when the local time or the world city crosses midnight. * * @param context The context in which the PendingIntent should perform the broadcast. *//*from w w w. j ava 2 s .co m*/ private void startAlarmOnQuarterHour(Context context) { if (context != null) { long onQuarterHour = Utils.getAlarmOnQuarterHour(); PendingIntent quarterlyIntent = getOnQuarterHourPendingIntent(context); AlarmManager alarmManager = ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.RTC, onQuarterHour, quarterlyIntent); } else { alarmManager.set(AlarmManager.RTC, onQuarterHour, quarterlyIntent); } } }
From source file:com.embeddedlog.LightUpDroid.DeskClock.java
private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); return true; case R.id.menu_item_help: Intent i = item.getIntent();/*from ww w . ja v a2s . c o m*/ if (i != null) { try { startActivity(i); } catch (ActivityNotFoundException e) { // No activity found to match the intent - ignore } } return true; case R.id.menu_item_night_mode: startActivity(new Intent(DeskClock.this, ScreensaverActivity.class)); case R.id.menu_item_sync_lightuppi: // TODO: update LightUpPiSync to actually sync alarms and then update this bit return true; case R.id.menu_item_push_to_lightuppi: // TODO: update LightUpPiSync to actually push alarms and then update this bit return true; case R.id.menu_item_push_to_phone: // TODO: update LightUpPiSync to actually push alarms and then update this bit String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX; new LightUpPiSync(this, correctString).syncPushToPhone(); return true; case R.id.menu_item_reset_db: // Delete the database ContentResolver cr = this.getContentResolver(); cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null); // Restart the app to repopulate db with default and recreate activities. Intent mStartActivity = new Intent(this, DeskClock.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); return true; default: break; } return true; }
From source file:com.numberx.kkmctimer.DeskClock.java
private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); return true; case R.id.menu_item_help: Intent i = item.getIntent();//from ww w .j a v a 2 s . c o m if (i != null) { try { startActivity(i); } catch (ActivityNotFoundException e) { // No activity found to match the intent - ignore } } return true; case R.id.menu_item_night_mode: startActivity(new Intent(DeskClock.this, ScreensaverActivity.class)); case R.id.menu_item_sync_kkmctimer: // TODO: update KKMCTimerSync to actually sync alarms and then update this bit return true; case R.id.menu_item_push_to_kkmctimer: // TODO: update KKMCTimerSync to actually push alarms and then update this bit return true; case R.id.menu_item_push_to_phone: // TODO: update KKMCTimerSync to actually push alarms and then update this bit String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX; new KKMCTimerSync(this, correctString).syncPushToPhone(); return true; case R.id.menu_item_reset_db: // Delete the database ContentResolver cr = this.getContentResolver(); cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null); // Restart the app to repopulate db with default and recreate activities. Intent mStartActivity = new Intent(this, DeskClock.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); return true; default: break; } return true; }
From source file:com.xperia64.timidityae.TimidityActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case PERMISSION_REQUEST: { // If request is cancelled, the result arrays are empty. boolean good = true; if (permissions.length != NUM_PERMISSIONS || grantResults.length != NUM_PERMISSIONS) { good = false;/*from w ww. j a v a 2s. com*/ } for (int i = 0; i < grantResults.length && good; i++) { if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { good = false; } } if (!good) { // permission denied, boo! Disable the app. //TODO: only disable if files are inaccessible new AlertDialog.Builder(TimidityActivity.this).setTitle("Error") .setMessage("Timidity AE cannot proceed without these permissions") .setPositiveButton("OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { TimidityActivity.this.finish(); } }).setCancelable(false).show(); } else { if (!Environment.getExternalStorageDirectory().canRead()) { // Buggy emulator? Try restarting the app AlarmManager alm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(this, 237462, new Intent(this, TimidityActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK)); System.exit(0); } yetAnotherInit(); } return; } // other 'case' lines to check for other // permissions this app might request } }
From source file:edu.mit.media.funf.probe.Probe.java
private void updateInternalRequestsPendingIntent() { PendingIntent internalPendingIntent = PendingIntent.getService(this, 0, requestsIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Keep the pending intent valid, by having the alarm clock keep a reference to it AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE); manager.set(AlarmManager.RTC, System.currentTimeMillis() + FAR_IN_FUTURE_MILLIS, internalPendingIntent); }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
@TargetApi(Build.VERSION_CODES.KITKAT) private void updateNextDayAlarm() { Intent intent = new Intent(this, NotificationUpdaterService.class); intent.setAction(ACTION_NEXT_DAY);/*from w ww . j a v a2 s . c o m*/ mDateChangePendingIntent = PendingIntent.getService(this, 0, intent, 0); // set alarm to update the next day GregorianCalendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DAY_OF_YEAR, 1); tomorrow.set(Calendar.HOUR_OF_DAY, 0); tomorrow.set(Calendar.MINUTE, 0); tomorrow.set(Calendar.SECOND, 0); tomorrow.set(Calendar.MILLISECOND, 0); AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { alarmManager.setWindow(AlarmManager.RTC, tomorrow.getTimeInMillis(), 1000, mDateChangePendingIntent); } else { alarmManager.set(AlarmManager.RTC, tomorrow.getTimeInMillis(), mDateChangePendingIntent); } }
From source file:org.zirco.ui.activities.MainActivity.java
/** * Restart the application.// ww w . jav a 2 s . c om */ public void restartApplication() { PendingIntent intent = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags()); AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent); System.exit(2); }