List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:com.google.android.gcm.demo.model.TaskTracker.java
public static TaskTracker createOneoff(String tag, long windowStartSecs, long windowEndSecs) { return new TaskTracker(tag, 0L, 0L, windowStartSecs, windowEndSecs, SystemClock.elapsedRealtime() / 1000); }
From source file:com.mgalgs.trackthatthing.LocationReceiver.java
public long getTimeSinceLastLoc_MS() { return (SystemClock.elapsedRealtime() - mLastLocTime); }
From source file:com.ivarprudnikov.sensors.OnBootBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Starts service responsible for sensor data storage Intent startSensorDataServiceIntent = new Intent(context, OnAlarmBroadcastReceiver.class); startSensorDataServiceIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT); PendingIntent pi1 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0); mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi1); // Registers alarms required for data export Intent startDataExportIntent = new Intent(context, OnExportAlarmBroadcastReceiver.class); startDataExportIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT); PendingIntent pi2 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0); mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi2); }
From source file:com.example.android.supportv4.app.SimpleJobIntentService.java
@Override protected void onHandleWork(Intent intent) { // We have received work to do. The system or framework is already // holding a wake lock for us at this point, so we can just go. Log.i("SimpleJobIntentService", "Executing work: " + intent); String label = intent.getStringExtra("label"); if (label == null) { label = intent.toString();//from ww w. j a v a 2 s . co m } toast("Executing: " + label); for (int i = 0; i < 5; i++) { Log.i("SimpleJobIntentService", "Running service " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(1000); } catch (InterruptedException e) { } } Log.i("SimpleJobIntentService", "Completed service @ " + SystemClock.elapsedRealtime()); }
From source file:com.heightechllc.breakify.AlarmNotifications.java
/** * Shows an ongoing notification for an upcoming alarm * @param context The context to create the notification from * @param ringTime The time that the alarm will ring, based on `SystemClock.elapsedRealtime()` * @param workState The work state of the timer *///from ww w .jav a2s. c om public static void showUpcomingNotification(Context context, long ringTime, int workState) { // Create the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_notification).setOngoing(true) .setPriority(NotificationCompat.PRIORITY_LOW); // Get the appropriate title based on the current work state int titleId = workState == MainActivity.WORK_STATE_WORKING ? R.string.notif_upcoming_title_working : R.string.notif_upcoming_title_breaking; builder.setContentTitle(context.getString(titleId)); // Get formatted time for when the alarm will ring. We need to convert `ringTime`, which // is based on `SystemClock.elapsedRealtime()`, to a regular Unix / epoch time long timeFromNow = ringTime - SystemClock.elapsedRealtime(); long ringUnixTime = System.currentTimeMillis() + timeFromNow; // Construct the text, e.g., "Until 11:30" String contentText = context.getString(R.string.notif_upcoming_content_text) + " "; contentText += DateFormat.getTimeFormat(context).format(new Date(ringUnixTime)); builder.setContentText(contentText); // Set up the action for the when the notification is clicked - to open MainActivity Intent mainIntent = new Intent(context, MainActivity.class); mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); // Show the notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationID, builder.build()); }
From source file:com.commonsware.android.deepbg.PollReceiver.java
static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, period, pi);/* w w w.ja v a 2 s. c om*/ }
From source file:com.handpoint.headstart.client.ui.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); HeadstartService.removeProperty("last_activity"); mPreferences = PreferenceManager.getDefaultSharedPreferences(this); long elapsedTime = SystemClock.elapsedRealtime(); long lastAttempt = getLastAttempt(); if (elapsedTime > lastAttempt && lastAttempt > 0 && lastAttempt + ATTEMPT_DELAY > elapsedTime) { long timeToWait = ATTEMPT_DELAY - (elapsedTime - lastAttempt); Toast.makeText(this, getString(R.string.warn_wait_message, formatTime(timeToWait)), Toast.LENGTH_LONG) .show();/* www . ja va2s .com*/ finish(); return; } setLastAttempt(0); setContentView(R.layout.login); Button loginButton = (Button) findViewById(R.id.login_button); loginButton.setOnClickListener(this); TextView forgotLink = (TextView) findViewById(R.id.forgot_password_link); SpannableString content = new SpannableString(getString(R.string.forgot_password_link_label)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); forgotLink.setText(content); forgotLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new ForgotPasscodeDialog(); newFragment.show(getSupportFragmentManager(), "forgot_passcode"); } }); }
From source file:com.licenta.android.licenseapp.alarm.AlarmReceiver.java
public static void setAlarm(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); /*//from ww w .j ava 2 s .c om * If you don't have precise time requirements, use an inexact repeating alarm * the minimize the drain on the device battery. * * The call below specifies the alarm type, the trigger time, the interval at * which the alarm is fired, and the alarm's associated PendingIntent. * It uses the alarm type RTC_WAKEUP ("Real Time Clock" wake up), which wakes up * the device and triggers the alarm according to the time of the device's clock. * * Alternatively, you can use the alarm type ELAPSED_REALTIME_WAKEUP to trigger * an alarm based on how much time has elapsed since the device was booted. This * is the preferred choice if your alarm is based on elapsed time--for example, if * you simply want your alarm to fire every 60 minutes. You only need to use * RTC_WAKEUP if you want your alarm to fire at a particular date/time. Remember * that clock-based time may not translate well to other locales, and that your * app's behavior could be affected by the user changing the device's time setting. * */ // Wake up the device to fire the alarm in 30 minutes, and every 30 minutes // after that. long intervalMillis; String intervalVal = prefs.getString("repeat_interval", "0"); switch (intervalVal) { case "15": intervalMillis = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case "30": intervalMillis = AlarmManager.INTERVAL_HALF_HOUR; break; case "60": intervalMillis = AlarmManager.INTERVAL_HOUR; break; default: intervalMillis = 0; break; } // for testing intervalMillis = 6000; alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + intervalMillis, intervalMillis, alarmIntent); prefs.edit().putBoolean(Constants.PREF_KEY_IS_ALARM_ON, true).apply(); Log.d(context.getClass().getName(), "Alarm started"); }
From source file:com.to8to.clickstream.network.BaseNetwork.java
@Override public NetworkBean performRequest(AbsRequest request) { long requestStart = SystemClock.elapsedRealtime(); while (true) { HttpResponse httpResponse = null; byte[] responseContents = null; Map<String, String> responseHeaders = new HashMap<String, String>(); try {/*from w w w.j a va2 s . c o m*/ // Gather headers. Map<String, String> headers = new HashMap<String, String>(); httpResponse = mHttpStack.performRequest(request); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); responseHeaders = convertHeaders(httpResponse.getAllHeaders()); responseContents = entityToBytes(httpResponse.getEntity()); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_NO_CONTENT) { throw new IOException(); } return new NetworkBean(statusCode, responseContents, responseHeaders); } catch (SocketTimeoutException e) { } catch (ConnectTimeoutException e) { } catch (MalformedURLException e) { } catch (IOException e) { } } }
From source file:com.example.hellonetwork.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w w w.java 2s . c om*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { for (int i = 0; i < loop; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(sleep); } catch (InterruptedException e) { Log.i("INTERRUPT", " "); } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } GcmReceiver.completeWakefulIntent(intent); }