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:com.xperia64.rompatcher.MainActivity.java
@SuppressLint("NewApi") @Override/*from ww w. ja v a 2s. c o m*/ 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; } 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. new AlertDialog.Builder(MainActivity.this).setTitle("Error") .setMessage("ROM Patcher cannot proceed without these permissions") .setPositiveButton("OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MainActivity.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, MainActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK)); System.exit(0); } } return; } // other 'case' lines to check for other // permissions this app might request } }
From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java
private static void clearReminder(Context context) { Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent);// ww w . ja v a 2 s .co m }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
/** * Starts (or stops) download and sets download icon appropriately */// ww w. j av a2 s . c o m private void startDownload() { listAdapter.saveData(); if (FileHandler.isDownloading) { DialogFactory.ActionDialogListener listener = new DialogFactory.ActionDialogListener() { @Override public void onClickRight(View v) { FileHandler.cancel(appContext); resetActionBarDownload(); dismissDialog(); } }; DialogFactory.showActionDialog(appContext, "", "Cancel download?", listener, -1, R.string.cancel_button, R.string.ok_button); } else if (FileHandler.download(appContext)) { Drawable drawable = getResources().getDrawable(R.drawable.ic_cancel_white_24dp); drawable.setColorFilter(AppSettings.getColorFilterInt(appContext), PorterDuff.Mode.MULTIPLY); toolbarMenu.getItem(1).setIcon(drawable); if (AppSettings.resetOnManualDownload() && AppSettings.useTimer() && AppSettings.getTimerDuration() > 0) { Intent intent = new Intent(); intent.setAction(LiveWallpaperService.DOWNLOAD_WALLPAPER); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + AppSettings.getTimerDuration(), AppSettings.getTimerDuration(), pendingIntent); } } }
From source file:com.negaheno.android.NotificationsController.java
private void scheduleNotificationRepeat() { try {//from w w w . j a va 2s. co m AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int minutes = preferences.getInt("repeat_messages", 60); if (minutes > 0 && personal_count > 0) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent); } else { alarm.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:org.wso2.iot.agent.services.operation.OperationManagerWorkProfile.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override/*from w w w.j av a2 s . co m*/ public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources()); if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) { Intent restrictionIntent = new Intent(getContext(), AppLockService.class); restrictionIntent.setAction(Constants.APP_LOCK_SERVICE); restrictionIntent.putStringArrayListExtra(Constants.AppRestriction.APP_LIST, (ArrayList) appRestriction.getRestrictedList()); PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, restrictionIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 1); // First time long frequency = 1 * 1000; // In ms alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), frequency, pendingIntent); getContext().startService(restrictionIntent); } else if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) { ArrayList appList = (ArrayList) appRestriction.getRestrictedList(); JSONArray whiteListApps = new JSONArray(); for (Object appObj : appList) { JSONObject app = new JSONObject(); try { app.put(Constants.AppRestriction.PACKAGE_NAME, appObj.toString()); app.put(Constants.AppRestriction.RESTRICTION_TYPE, Constants.AppRestriction.WHITE_LIST); whiteListApps.put(app); } catch (JSONException e) { operation.setStatus(getContextResources().getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing app white-list payload."); getResultBuilder().build(operation); throw new AndroidAgentException("Invalid JSON format for app white-list bundle.", e); } } Preference.putString(getContext(), Constants.AppRestriction.WHITE_LIST_APPS, whiteListApps.toString()); validateInstalledApps(); } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:org.chromium.chrome.browser.physicalweb.UrlManager.java
private void scheduleClearNotificationAlarm() { PendingIntent pendingIntent = createClearNotificationAlarmIntent(); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); long time = SystemClock.elapsedRealtime() + STALE_NOTIFICATION_TIMEOUT_MILLIS; alarmManager.set(AlarmManager.ELAPSED_REALTIME, time, pendingIntent); }
From source file:com.money.manager.ex.sync.SyncManager.java
private AlarmManager getAlarmManager() { return (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); }
From source file:org.chromium.chrome.browser.physicalweb.UrlManager.java
private void cancelClearNotificationAlarm() { PendingIntent pendingIntent = createClearNotificationAlarmIntent(); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent);// ww w.ja v a2 s . c om }
From source file:com.negaheno.android.NotificationsController.java
private void scheduleNotificationDelay(boolean onlineReason) { try {/*from w ww. j av a2s .c om*/ FileLog.e("tmessages", "delay notification start"); AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (onlineReason) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent); } else { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.notalenthack.blaster.CommandActivity.java
private void startStatusUpdate() { // Setup expiration if we never get a message from the service AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(); intent.setAction(Constants.ACTION_REFRESH_STATUS); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Set repeating updating of status, will need to cancel if activity is gone Calendar cal = Calendar.getInstance(); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), Constants.UPATE_STATUS_PERIOD * 1000, pi); }