List of usage examples for android.content Context ALARM_SERVICE
String ALARM_SERVICE
To view the source code for android.content Context ALARM_SERVICE.
Click Source Link
From source file:org.ohmage.reminders.notif.Notifier.java
private static void setAlarm(Context context, String action, int mins, Bundle extras) { Log.v(TAG, "Notifier: Setting alarm(" + mins + ", " + action + ")"); AlarmManager alarmMan = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, NotifReceiver.class).setAction(action); if (extras != null) { i.putExtras(extras);//from w w w . j a v a 2 s.co m } PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); long elapsed = mins * 60 * 1000; alarmMan.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + elapsed, pi); }
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/* ww w . j a va2s. 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:com.android.providers.downloads.DownloadService.java
/** * Initializes the service when it is first created *///from w ww . ja v a 2s. c om @Override public void onCreate() { super.onCreate(); XLConfig.LOGD("(onCreate) ---> Service onCreate"); if (mSystemFacade == null) { mSystemFacade = new RealSystemFacade(this); } mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mStorageManager = new StorageManager(this); mUpdateThread = new HandlerThread(Constants.TAG + "-UpdateThread"); mUpdateThread.start(); mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback); mScanner = new DownloadScanner(this); mNotifier = new DownloadNotifier(this); mNotifier.cancelAll(); mObserver = new DownloadManagerContentObserver(); getContentResolver().registerContentObserver(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, true, mObserver); // get mXunleiEngineEnable from DB mXunleiEngineEnable = Helpers.getXunleiUsagePermission(getApplicationContext()); if (mXunleiEngineEnable) { startGetXlTokenEx(false); initXunleiEngine(); } if (!miui.os.Build.IS_TABLET) { mCdnThread = new CdnQueryingThread(); mCdnThread.start(); } if (XLUtil.getNetwrokType(getApplicationContext()) == ConnectivityManager.TYPE_MOBILE) { mCloudControlThread = new MobileCloudCheckThread(); mCloudControlThread.start(); } String pkgName = getApplicationContext().getPackageName(); Helpers.trackDownloadServiceStatus(this.getApplicationContext(), DOWNLOAD_SERVICE_START, pkgName); // do track // Context ctx = getApplicationContext(); // String pkgName = ctx.getPackageName(); // Helpers.trackOnlineStatus(ctx, 0, 0, mXunleiEngineEnable, "", "", pkgName, PRODUCT_NAME, PRODUCT_VERSION); }
From source file:alaindc.crowdroid.SendIntentService.java
private void handleActionReceivedData(String response) { // Data got from server response int timeout; // sec double radius; // meters int sensor;/* w w w . j av a2 s. co m*/ double latitude, longitude; // Update view sending a broadcast intent Intent intent = new Intent(Constants.INTENT_RECEIVED_DATA); intent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, response); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); try { JSONArray jsonArray = new JSONArray(response); JSONObject jsonObject = jsonArray.getJSONObject(0); sensor = jsonObject.getInt("sensor"); // For time homogeneity timeout = jsonObject.getInt("timeout"); // For space homogeneity radius = jsonObject.getDouble("radius"); latitude = jsonObject.getDouble("lat"); longitude = jsonObject.getDouble("long"); } catch (JSONException e) { return; } if (sensor == Constants.TYPE_TEL) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean(Constants.THROUGHPUT_TAKEN, false); editor.commit(); } Intent geofenceIntent = new Intent(getApplicationContext(), GeofenceIntentService.class); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_SENSORTYPE, sensor); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_LATITUDE, latitude); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_LONGITUDE, longitude); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_RADIUS, String.valueOf(radius)); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_EXPIRE_MILLISEC, String.valueOf(timeout * 1000)); getApplicationContext().startService(geofenceIntent); // Set timeout based on server response alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SendIntentService.class); intentAlarm.setAction(Constants.ACTION_SENDDATA + sensor); intentAlarm.putExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND, sensor); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); int seconds = timeout; alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); }
From source file:com.androidinspain.deskclock.Utils.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static String getNextAlarmLOrLater(Context context) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final AlarmClockInfo info = getNextAlarmClock(am); if (info != null) { final long triggerTime = info.getTriggerTime(); final Calendar alarmTime = Calendar.getInstance(); alarmTime.setTimeInMillis(triggerTime); return AlarmUtils.getFormattedTime(context, alarmTime); }//from w w w . java2 s .c o m return null; }
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void scheduleAutoUpdates() { if (!PrefUtils.shouldAutoUpdate(this)) { return;/*from www . ja va 2 s . co m*/ } final long currentTime = TimeUtils.getUTCTime(); final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this, UpdateMatchService.class); final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class); final long matchUpdateTime = currentTime + (60000 * 60 * 12); final long resultUpdateTime = currentTime + (60000 * 60); PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.cancel(umi); am.cancel(uri); am.setInexactRepeating(AlarmManager.RTC, matchUpdateTime, AlarmManager.INTERVAL_HALF_DAY, umi); am.setInexactRepeating(AlarmManager.RTC, resultUpdateTime, AlarmManager.INTERVAL_HOUR, uri); }
From source file:com.razza.apps.iosched.service.SessionAlarmService.java
public void scheduleFeedbackAlarm(final long sessionEnd, final long alarmOffset, final String sessionTitle) { // By default, feedback alarms fire 5 minutes before session end time. If alarm offset is // provided, alarm is set to go off that much time from now (useful for testing). long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionEnd - MILLI_FIVE_MINUTES; } else {//ww w . ja v a 2 s. co m alarmTime = UIUtils.getCurrentTime(this) + alarmOffset; } LogUtils.LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'"); LogUtils.LOGD(TAG, " -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString()); LogUtils.LOGD(TAG, " -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent feedbackIntent = new Intent(ACTION_NOTIFY_SESSION_FEEDBACK, null, this, SessionAlarmService.class); PendingIntent pi = PendingIntent.getService(this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.hodor.company.areminder.ui.MainActivity.java
private void registerAlarmManager(long duration) { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(ACTION_SHOW_ALARM, null, this, TimerService.class); intent.putExtra("category", category.ordinal()); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); long time = System.currentTimeMillis() + duration; alarmManager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent); }
From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java
public void scheduleFeedbackAlarm(final long sessionEnd, final long alarmOffset, final String sessionTitle) { // By default, feedback alarms fire 5 minutes before session end time. If alarm offset is // provided, alarm is set to go off that much time from now (useful for testing). long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionEnd - MILLI_FIVE_MINUTES; } else {//from ww w . j a v a 2 s.c om alarmTime = UIUtils.getCurrentTime(this) + alarmOffset; } LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'"); LOGD(TAG, " -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString()); LOGD(TAG, " -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent feedbackIntent = new Intent(ACTION_NOTIFY_SESSION_FEEDBACK, null, this, SessionAlarmService.class); PendingIntent pi = PendingIntent.getService(this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java
/** * The alarm manager for the application. */ private AlarmManager getAlarmManager() { return (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); }