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.pacoapp.paco.triggering.NotificationCreator.java
@SuppressLint("NewApi") private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) { DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime()); Experiment experiment = experimentProviderUtil .getExperimentByServerId(notificationHolder.getExperimentId()); Integer snoozeTime = notificationHolder.getSnoozeTime(); if (snoozeTime == null) { snoozeTime = DEFAULT_SNOOZE_10_MINUTES; }//from w ww. j a va2 s .c o m int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE; DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes); long snoozeDurationInMillis = timeoutMinutes.getMillis(); Log.info("Creating snooze alarm to resound notification for holder: " + notificationHolder.getId() + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = " + new DateTime(alarmTime).toString() + " waking up from snooze in " + timeoutMinutes + " minutes"); Intent ultimateIntent = new Intent(context, AlarmReceiver.class); Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI, notificationHolder.getId().toString()); ultimateIntent.setData(uri); ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); ultimateIntent.putExtra(SNOOZE_REPEATER_EXTRA_KEY, true); PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 3, ultimateIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(intent); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); } }
From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java
private void c2dmHandleRegistrationResponse(final Context context, Intent intent) { Log.d(TAG, "c2dmHandleRegistrationResponse: context=" + context + ", intent=" + intent + ", extras=" + Utils.bundleToString(intent.getExtras())); final String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID); String error = intent.getStringExtra(EXTRA_ERROR); String unregistered = intent.getStringExtra(EXTRA_UNREGISTERED); Log.d(TAG, "handleRegistration: registrationId = " + registrationId + ", error = " + error + ", unregistered = " + unregistered); mConfiguration.putLong(LAST_CHANGE, System.currentTimeMillis()); if (unregistered != null) { // Unregistered mConfiguration.putString(REG_ID, ""); setStateAndNotify(REGISTRATION_STATE_UNREGISTERING, REGISTRATION_SUBSTATE_NONE); mHandler.sendEmptyMessage(EVENT_UNREGISTER_COMPLETE); } else if (error != null) { // Registration failed. Log.e(TAG, "Registration error " + error); mConfiguration.putString(REG_ID, ""); setStateAndNotify(REGISTRATION_STATE_ERROR, error); if ("SERVICE_NOT_AVAILABLE".equals(error)) { long backoffTime = mConfiguration.getLong(C2DM_BACKOFF, DEFAULT_BACKOFF); // For this error, try again later. Log.d(TAG, "Scheduling registration retry, backoff = " + backoffTime); Intent retryIntent = new Intent(C2DM_INTENT_RETRY); PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 0 /* requestCode */, retryIntent, 0 /* flags */); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, backoffTime, retryPIntent); // Next retry should wait longer. backoffTime *= BACKOFF_MULTIPLIER; if (backoffTime > MAX_BACKOFF) { backoffTime = MAX_BACKOFF; mConfiguration.putLong(C2DM_BACKOFF, backoffTime); }/*from w w w.jav a2 s .c o m*/ // Save the backoff time. writePreferences(); } } else { mConfiguration.putString(REG_ID, registrationId); setStateAndNotify(REGISTRATION_STATE_REGISTERING, REGISTRATION_SUBSTATE_HAVE_REG_ID); mHandler.sendEmptyMessage(EVENT_REGISTER_COMPLETE); } }
From source file:org.wso2.cdm.agent.AuthenticationActivity.java
private void startLocalNotification(Float interval) { long firstTime = SystemClock.elapsedRealtime(); firstTime += 1 * 1000;//from w w w . j a v a 2 s .c om Intent downloader = new Intent(context, AlarmReceiver.class); PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Float seconds = interval; if (interval < 1.0) { alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, seconds.intValue(), recurringDownload); } else { alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, seconds.intValue(), recurringDownload); } }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Called when download has been completed. * @param content content.//from ww w . ja v a2 s . c om */ void onDownloadComplete(EngagementReachInteractiveContent content) { /* Cancel alarm */ Intent intent = new Intent(INTENT_ACTION_DOWNLOAD_TIMEOUT); intent.setPackage(mContext.getPackageName()); int requestCode = (int) content.getLocalId(); PendingIntent operation = PendingIntent.getBroadcast(mContext, requestCode, intent, 0); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(operation); /* Update notification if not too late e.g. notification not yet dismissed */ notifyPendingContent(content); }
From source file:org.wso2.emm.agent.services.operation.OperationManagerOlderSdk.java
@Override public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources());// www.ja v a 2 s. c om String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE); if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) { if (Constants.OWNERSHIP_COPE.equals(ownershipType)) { List<String> installedAppPackages = CommonUtils.getInstalledAppPackages(getContext()); List<String> toBeHideApps = new ArrayList<>(installedAppPackages); toBeHideApps.removeAll(appRestriction.getRestrictedList()); for (String packageName : toBeHideApps) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } } else if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) { if (Constants.OWNERSHIP_BYOD.equals(ownershipType)) { 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.OWNERSHIP_COPE.equals(ownershipType)) { for (String packageName : appRestriction.getRestrictedList()) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:org.wso2.iot.agent.services.operation.OperationManagerBYOD.java
@Override public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources());// w w w. ja v a 2s . c o m String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE); if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) { //Persisting white-listed app list. JSONArray whiteListApps = new JSONArray(); ArrayList appList = (ArrayList) appRestriction.getRestrictedList(); 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); } } if (Constants.OWNERSHIP_COPE.equals(ownershipType)) { //Removing existing non-white-listed apps. List<String> installedAppPackages = CommonUtils.getInstalledAppPackages(getContext()); List<String> toBeHideApps = new ArrayList<>(installedAppPackages); toBeHideApps.removeAll(appList); for (String packageName : toBeHideApps) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } Preference.putString(getContext(), Constants.AppRestriction.WHITE_LIST_APPS, whiteListApps.toString()); } else if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) { if (Constants.OWNERSHIP_BYOD.equals(ownershipType)) { 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.OWNERSHIP_COPE.equals(ownershipType)) { for (String packageName : appRestriction.getRestrictedList()) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:com.mobicage.rogerthat.MainService.java
@Override public int onStartCommand(Intent intent, int flags, int startid) { T.UI();//from w w w . jav a 2 s. com super.onStartCommand(intent, flags, startid); final Bundle extras = intent == null ? null : intent.getExtras(); boolean launchedAtBootTime = false; boolean launchedByBgDataSettingChange = false; boolean launchedByOnCreate = false; boolean launchedByJustRegistered = false; boolean launchedByGCM = false; try { if (extras != null) { launchedAtBootTime = extras.getBoolean(START_INTENT_BOOTTIME_EXTRAS_KEY, false); launchedByBgDataSettingChange = extras .getBoolean(START_INTENT_BACKGROUND_DATA_SETTING_CHANGED_EXTRAS_KEY, false); launchedByOnCreate = extras.getBoolean(START_INTENT_FROM_ONCREATE_KEY, false); launchedByJustRegistered = extras.getBoolean(START_INTENT_JUST_REGISTERED, false); launchedByGCM = extras.getBoolean(START_INTENT_GCM, false); } if (launchedByGCM) { kickHttpCommunication(true, "Incomming GCM"); return START_STICKY; } final boolean isRegisteredInConfig = getRegisteredFromConfig(); L.d("MainService.onStart \n isIntentNull = " + (intent == null) + "\n isRegisteredInConfig = " + isRegisteredInConfig + "\n launchedAtBootTime = " + launchedAtBootTime + "\n launchedByBgDataSettingChange = " + launchedByBgDataSettingChange + "\n launchedByOnCreate = " + launchedByOnCreate + "\n launchedByJustRegistered = " + launchedByJustRegistered); if (launchedByJustRegistered) { setupNetworkProtocol(); final String myEmail = extras == null ? null : extras.getString(START_INTENT_MY_EMAIL); initializeService(myEmail); } if (!isRegisteredInConfig) { L.d("MainService.onStart() - stopping service immediately"); stopSelf(); return START_NOT_STICKY; } // start networking machinery if (CloudConstants.USE_XMPP_KICK_CHANNEL) mXmppKickChannel.start(); getPlugin(SystemPlugin.class).doHeartbeat(); if (CloudConstants.USE_GCM_KICK_CHANNEL) GoogleServicesUtils.registerGCMRegistrationId(this, null); if (launchedByOnCreate) { kickHttpCommunication(true, "We just got started"); } cleanupOldCachedFiles(false); PendingIntent cleanupDownloadsIntent = PendingIntent.getBroadcast(this, 0, new Intent(INTENT_SHOULD_CLEANUP_CACHED_FILES), 0); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + AlarmManager.INTERVAL_DAY * 7, AlarmManager.INTERVAL_DAY * 7, cleanupDownloadsIntent); return START_STICKY; } finally { if (launchedByGCM) { GCMReveiver.completeWakefulIntent(intent); } } }
From source file:com.guardtrax.ui.screens.HomeScreen.java
@Override public void onResume() { //if exiting from the scan screen with an unregistered app if (GTConstants.exitingScanScreen && !Utility.deviceRegistered()) onBackPressed();/*from w ww. j ava 2s .co m*/ //if this is a newly registered app then reboot if (newRegistration && Utility.deviceRegistered()) { try { Intent restartIntent = getPackageManager().getLaunchIntentForPackage(getPackageName()); PendingIntent intent = PendingIntent.getActivity(HomeScreen.this, 0, restartIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); manager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, intent); System.exit(2); } catch (Exception e) { Toast.makeText(getApplicationContext(), "ON RESUME ERROR: " + e, Toast.LENGTH_LONG).show(); } } else { if (!ScreenReceiver.wasScreenOn) { //Toast.makeText(getApplicationContext(), "ON RESUME", Toast.LENGTH_LONG).show(); //if(ftpDownload.getStatus() != AsyncTask.Status.RUNNING)syncFTP(); //syncFTP(); } syncFTP(); setuserBanner(); //if returning from tag scan for time and attendance after an end shift then taa was set to 1 //set taa to 2 and then launch dialog to display the time and attendance record and then signature page if (taa == 1) { taa = 0; } if (taa == 2) { //write to tar, transfer file to send directory Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.tarfileName, "End shift;" + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n", true); //write additional info to tar file Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.tarfileName, "Total Time;" + Utility.gettimeDiff(Utility.getsessionStart(), Utility.getLocalDateTime()) + "\r\n" + "Time on Lunch;" + lunchTime + "\r\n" + "Time on Break;" + breakTime + "\r\n", true); //give time for file write Utility.initializeGeneralTimer(2000); do { Utility.Sleep(100); } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag()); lunchTime = "00:00:00:00"; breakTime = "00:00:00:00"; taa = 5; show_taaSignature_dialog(); //returning from end shift location scan } if (taa == 3) { //write the event 25 information to the file String GM = ""; if (GTConstants.isSignature) { GM = Utility.getHeaderMessage("$GM") + ",25," + getCellID() + CRLF + "***SIGNATURE***" + CRLF + Utility.getsharedPreference(HomeScreen.this, "signaturefileName"); GTConstants.isSignature = false; signaturefileName = ""; } else GM = Utility.getHeaderMessage("$GM") + ",25," + getCellID(); Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.tarfileName, GM + "\r\n", true); //give time for file write Utility.initializeGeneralTimer(2000); do { Utility.Sleep(100); } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag()); //move the tar file to the send file folder File from = new File(GTConstants.dardestinationFolder, GTConstants.tarfileName); //change the file name to match the $GM time and date String[] parse = GM.split(","); String newFile = GTConstants.LICENSE_ID.substring(7) + "_" + parse[10] + "_" + parse[2] + "_tar.tar"; File to = new File(GTConstants.sendfileFolder, newFile); from.renameTo(to); endshiftCode(); taa = 0; } //check if the tag is in a tour if (GTConstants.exitingScanScreen) { if (GTConstants.isTour) { if (GTConstants.tourName.length() == 1) { if (getlasttagScanned().length() == 16) show_tours_dialog(true); } else { updateTour(getlasttagScanned()); } } //check if this is an account setup tag, designated by an "@&" as the first two characters if (getlasttagScanned().length() == 16) { String temp = Utility.get_from_GTParamsDataBase(HomeScreen.this, getlasttagScanned()); if (temp.contains("@&")) { temp = temp.substring(2); setupAccounts("0", temp); //Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_LONG).show(); } } GTConstants.exitingScanScreen = false; } } super.onResume(); }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
public void setAlarm(Context context) { cancelAlarm(context);//from w w w . j a va2s . co m AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, BackgroundService.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60, pendingIntent); }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
public void cancelAlarm(Context context) { Intent intent = new Intent(context, BackgroundService.class); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(sender);//from w w w. j a v a2s . c om }