List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:com.android.anton.pushnotificationwithgcm.GCMUtil.MyGcmListenerService.java
@Override public void onTaskRemoved(Intent rootIntent) { Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass()); restartServiceIntent.setPackage(getPackageName()); PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent); super.onTaskRemoved(rootIntent); }
From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.youku.player.service.GetVideoUrlServiceYouku.java
/** * @return VideoUrlInfo/* ww w . j av a 2s . co m*/ * @param vid * @param languageCode * @param videostage * @param format * @param resetProgress * @param local_history */ public void getVideoUrl(String vid, String languageCode, int videostage, int format, VideoUrlInfo mVideoUrlInfo, boolean resetProgress, String local_vid, String local_time, String local_history, IVideoInfoCallBack mListener) { String url = null; this.resetProgress = resetProgress; languageCode = URLEncoder(languageCode); if (Profile.USE_SYSTEM_PLAYER) { this.format = "6"; } else // ??? if (Profile.FORMAT_FLV_HD == format) { this.format = "1,5,6,7,8"; } else { this.format = "4"; } final String password = mVideoUrlInfo.password; final String playlistId = mVideoUrlInfo.playlistId; if (videostage != 0) {// url String mUrlMoreYouku = URLContainer.getMutilPayVideoPlayUrl(vid, password, local_time, videostage, local_vid, languageCode, this.format, local_history, playlistId); /* * URLContainer.getMutilVideoUrlYouku(vid, languageCode, videostage, * this.format); */ url = mUrlMoreYouku; } else {// ?url String mUrlOneYouku = URLContainer.getOnePayVideoPlayUrl(vid, password, local_time, local_vid, languageCode, this.format, local_history, playlistId); /* * URLContainer.getOneVideoUrlYouku(vid, languageCode, this.format); */ url = mUrlOneYouku; } h265 = MediaPlayerConfiguration.getInstance().useH265() && MediaPlayerProxy.supportH265(); if (h265) url += "&h265=1"; this.mListener = mListener; this.mVideoUrlInfo = mVideoUrlInfo; Logger.d(LogTag.TAG_PLAYER, "? GetVideoUrlServiceYouku getVideoUrl:" + url); mGetPlayListTime = SystemClock.elapsedRealtime(); TaskGetVideoUrl taskGetVideoUrl = new TaskGetVideoUrl(url); taskGetVideoUrl.setSuccess(SUCCESS); taskGetVideoUrl.setFail(FAIL); taskGetVideoUrl.execute(handler); }
From source file:cs460.grouple.grouple.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { GLOBAL = ((Global) getApplicationContext()); EXTRAS = intent.getExtras();//from ww w. j a v a2 s . c o m MESSAGE = EXTRAS.getString("msg"); SENDER = EXTRAS.getString("sender"); RECEIVER = EXTRAS.getString("receiver"); TYPE = EXTRAS.getString("content"); NAME = EXTRAS.getString("name"); if (TYPE != null) { if (TYPE.equals(CONTENT_TYPE.GROUP_MESSAGE.toString()) || TYPE.equals(CONTENT_TYPE.EVENT_MESSAGE.toString()) || TYPE.equals(CONTENT_TYPE.USER_MESSAGE.toString()) || TYPE.equals(CONTENT_TYPE.FRIEND_REQUEST.toString()) || TYPE.equals(CONTENT_TYPE.EVENT_INVITE.toString()) || TYPE.equals(CONTENT_TYPE.EVENT_INVITE.toString())) { SENDER_FIRST = EXTRAS.getString("first"); SENDER_LAST = EXTRAS.getString("last"); } } // String test = EXTRAS.getString("my_action"); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!EXTRAS.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that * GCM will be extended in the future with new message types, just * ignore any message types you're not interested in, or that you * don't recognize. */ 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()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification(MESSAGE); Log.i(TAG, "Received: " + EXTRAS.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AutomuteAlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.rickendirk.rsgwijzigingen.ZoekService.java
private void setAlarmIn20Min() { Intent zoekIntent = new Intent(this, ZoekService.class); zoekIntent.putExtra("isAchtergrond", true); zoekIntent.addCategory("GeenWifiHerhaling"); //Categorie om andere intents cancelen te voorkomen PendingIntent pendingIntent = PendingIntent.getService(this, 3, zoekIntent, PendingIntent.FLAG_ONE_SHOT); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Long in20Min = SystemClock.elapsedRealtime() + 1200000; //20Min in milisec. manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, in20Min, pendingIntent); Log.i(TAG, "Nieuw alarm gezet in 20 min"); }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
@Override public void postponeAlarm(long delayTimeInMillis) { long triggerTime = SystemClock.elapsedRealtime() + delayTimeInMillis; Calendar nextAlarmTime = Calendar.getInstance(); nextAlarmTime.add(Calendar.MILLISECOND, (int) delayTimeInMillis); Utils.setNextAlarmTimeString(nextAlarmTime, mContext); setAlarm(triggerTime);/*from w w w. j a v a 2 s . co m*/ }
From source file:ch.carteggio.provider.sync.NotificationService.java
protected void onHandleIntent(Intent intent) { if (intent != null) { if (UPDATE_RECEIVING_STATE_ACTION.equals(intent.getAction())) { mReceiveFailure = intent.getBooleanExtra(FAILURE_EXTRA, true); mReceiveMessage = intent.getStringExtra(FAILURE_MESSAGE_EXTRA); if (!mReceiveFailure) { mLastReceiveSuccessTime = SystemClock.elapsedRealtime(); }/*from w ww.j av a 2 s .c om*/ } else if (UPDATE_SENDING_STATE_ACTION.equals(intent.getAction())) { mSendFailure = intent.getBooleanExtra(FAILURE_EXTRA, true); mSendMessage = intent.getStringExtra(FAILURE_MESSAGE_EXTRA); if (!mSendFailure) { mLastSendSuccessTime = SystemClock.elapsedRealtime(); } } else if (UPDATE_UNREAD_STATE_ACTION.equals(intent.getAction())) { boolean newMessage = intent.getBooleanExtra(NEW_MESSAGE_EXTRA, false); updateUnreadNotification(newMessage); } } // update the notifications if ((mSendFailure && SystemClock.elapsedRealtime() - mLastSendSuccessTime > DISCONNECTION_TIME_THRESHOLD) || (mReceiveFailure && SystemClock.elapsedRealtime() - mLastReceiveSuccessTime > DISCONNECTION_TIME_THRESHOLD)) { showFailureNotification(); } else { hideFailureNotification(); } // inform UI of the changes broadcastNetworkStateChange(); }
From source file:com.develop.autorus.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Fabric.with(this, new Crashlytics()); super.onCreate(savedInstanceState); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); AnalyticsApplication application = (AnalyticsApplication) getApplication(); mTracker = application.getDefaultTracker(); mTracker.setScreenName("Main activity"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); if (pref.getBoolean("notificationIsActive", true)) { Intent checkIntent = new Intent(getApplicationContext(), MonitoringWork.class); Boolean alrarmIsActive = false; if (PendingIntent.getService(getApplicationContext(), 0, checkIntent, PendingIntent.FLAG_NO_CREATE) != null) alrarmIsActive = true;/* ww w. j a v a 2 s . c o m*/ am = (AlarmManager) getSystemService(ALARM_SERVICE); if (!alrarmIsActive) { Intent serviceIntent = new Intent(getApplicationContext(), MonitoringWork.class); PendingIntent pIntent = PendingIntent.getService(getApplicationContext(), 0, serviceIntent, 0); int period = pref.getInt("numberOfActiveMonitors", 0) * 180000; if (period != 0) am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, period, pIntent); } } /*ForEasyDelete //Danger! Auchtung! ?, !!! String base64EncodedPublicKey = "<your license key here>";//? . !!! ? , // github ? . ?!!! mHelper = new IabHelper(this, base64EncodedPublicKey); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { Log.d(TAG, "In-app Billing setup failed: " + result); } else { Log.d(TAG, "In-app Billing is set up OK"); } } }); */ //Service inapp Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); intent.setPackage("com.android.vending"); blnBind = bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE); String themeName = pref.getString("theme", "1"); if (themeName.equals("1")) { setTheme(R.style.AppTheme); if (android.os.Build.VERSION.SDK_INT >= 21) { Window statusBar = getWindow(); statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor)); } } else if (themeName.equals("2")) { setTheme(R.style.AppTheme2); if (android.os.Build.VERSION.SDK_INT >= 21) { Window statusBar = getWindow(); statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor2)); } } ThemeManager.init(this, 2, 0, null); if (isFirstLaunch) { SQLiteDatabase db = new DbHelper(this).getWritableDatabase(); Cursor cursorMonitors = db.query("monitors", null, null, null, null, null, null); Boolean monitorsExist = cursorMonitors != null && cursorMonitors.getCount() > 0; db.close(); if (getSupportFragmentManager().findFragmentByTag("MAIN") == null) { FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction(); if (monitorsExist) mainFragment = SearchAndMonitorsFragment.newInstance(0); else mainFragment = SearchAndMonitorsFragment.newInstance(1); fTrans.add(R.id.container, mainFragment, "MAIN").commit(); } else { mainFragment = (SearchAndMonitorsFragment) getSupportFragmentManager().findFragmentByTag("MAIN"); if (getSupportFragmentManager().findFragmentByTag("Second") != null) { FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction(); fTrans.remove(getSupportFragmentManager().findFragmentByTag("Second")).commit(); } pref.edit().remove("NumberOfCallingFragment"); } } backToast = Toast.makeText(this, "? ? ", Toast.LENGTH_SHORT); setContentView(R.layout.main_activity); mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); mSnackBar = (SnackBar) findViewById(R.id.main_sn); setSupportActionBar(mToolbar); addMonitorButton = (Button) findViewById(R.id.toolbar_add_monitor_button); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.fragment_drawer); mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar); Thread threadAvito = new Thread(new Runnable() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void run() { Document doc; SharedPreferences sPref; try { String packageName = getApplicationContext().getPackageName(); doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + packageName).userAgent( "Mozilla/5.0 (Windows; U; WindowsNT 5.1; ru-RU; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6") .timeout(12000).get(); //"") PackageManager packageManager; PackageInfo packageInfo; packageManager = getPackageManager(); packageInfo = packageManager.getPackageInfo(getPackageName(), 0); Element mainElems = doc.select( "#body-content > div > div > div.main-content > div.details-wrapper.apps-secondary-color > div > div.details-section-contents > div:nth-child(4) > div.content") .first(); if (!packageInfo.versionName.equals(mainElems.text())) { sPref = getPreferences(MODE_PRIVATE); SharedPreferences.Editor ed = sPref.edit(); ed.putBoolean(SAVED_TEXT_WITH_VERSION, false); ed.commit(); } else { sPref = getPreferences(MODE_PRIVATE); SharedPreferences.Editor ed = sPref.edit(); ed.putBoolean(SAVED_TEXT_WITH_VERSION, true); ed.commit(); } //SharedPreferences sPrefRemind; //sPrefRemind = getPreferences(MODE_PRIVATE); //sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit(); } catch (HttpStatusException e) { return; } catch (IOException e) { return; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }); SharedPreferences sPrefVersion; sPrefVersion = getPreferences(MODE_PRIVATE); Boolean isNewVersion; isNewVersion = sPrefVersion.getBoolean(SAVED_TEXT_WITH_VERSION, true); threadAvito.start(); boolean remind = true; if (!isNewVersion) { Log.d("affa", "isNewVersion= " + isNewVersion); SharedPreferences sPref12; sPref12 = getPreferences(MODE_PRIVATE); String isNewVersion12; PackageManager packageManager; PackageInfo packageInfo; packageManager = getPackageManager(); try { packageInfo = packageManager.getPackageInfo(getPackageName(), 0); isNewVersion12 = sPref12.getString("OldVersionName", packageInfo.versionName); if (!isNewVersion12.equals(packageInfo.versionName)) { SharedPreferences sPref; sPref = getPreferences(MODE_PRIVATE); SharedPreferences.Editor ed = sPref.edit(); ed.putBoolean(SAVED_TEXT_WITH_VERSION, false); ed.commit(); SharedPreferences sPrefRemind; sPrefRemind = getPreferences(MODE_PRIVATE); sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit(); } else remind = false; SharedPreferences sPrefRemind; sPrefRemind = getPreferences(MODE_PRIVATE); sPrefRemind.edit().putString("OldVersionName", packageInfo.versionName).commit(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } SharedPreferences sPrefRemind; sPrefRemind = getPreferences(MODE_PRIVATE); Boolean dontRemind; dontRemind = sPrefRemind.getBoolean(DO_NOT_REMIND, false); Log.d("affa", "dontRemind= " + dontRemind.toString()); Log.d("affa", "remind= " + remind); Log.d("affa", "44444444444444444444444= "); if ((!dontRemind) && (!remind)) { Log.d("affa", "5555555555555555555555555= "); SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) { @Override public void onPositiveActionClicked(DialogFragment fragment) { super.onPositiveActionClicked(fragment); String packageName = getApplicationContext().getPackageName(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)); startActivity(intent); } @Override public void onNegativeActionClicked(DialogFragment fragment) { super.onNegativeActionClicked(fragment); } @Override public void onNeutralActionClicked(DialogFragment fragment) { super.onNegativeActionClicked(fragment); SharedPreferences sPrefRemind; sPrefRemind = getPreferences(MODE_PRIVATE); sPrefRemind.edit().putBoolean(DO_NOT_REMIND, true).commit(); } }; builder.message( " ?? ? ? ?") .title(" !").positiveAction("") .negativeAction("").neutralAction("? "); DialogFragment fragment = DialogFragment.newInstance(builder); fragment.show(getSupportFragmentManager(), null); } } }
From source file:com.nagopy.android.xposed.utilities.ModBrightness.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @XMinSdkVersion(Build.VERSION_CODES.JELLY_BEAN_MR1) @InitZygote(summary = "??") public static void brightnessDebugger(final StartupParam startupParam, final ModBrightnessSettingsGen settings) throws Throwable { if (!settings.brightnessDebugger) { return;// ww w .j ava 2 s .c o m } // DisplayPowerController?? final Class<?> displayPowerContoroll = XposedHelpers .findClass("com.android.server.power.DisplayPowerController", null); // Context? XposedBridge.hookAllConstructors(displayPowerContoroll, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Context context = (Context) param.args[1]; XposedHelpers.setAdditionalInstanceField(param.thisObject, "mContext", context); XLog.d("mScreenAutoBrightnessSpline", XposedHelpers.getObjectField(param.thisObject, "mScreenAutoBrightnessSpline")); } }); XposedHelpers.findAndHookMethod(displayPowerContoroll, "updateAutoBrightness", boolean.class, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { if (SystemClock.elapsedRealtime() < 60 * 1000) { // ???? return; } Context mContext = (Context) XposedHelpers.getAdditionalInstanceField(param.thisObject, "mContext"); Object mScreenAutoBrightness = XposedHelpers.getObjectField(param.thisObject, "mScreenAutoBrightness"); Object mAmbientLux = XposedHelpers.getObjectField(param.thisObject, "mAmbientLux"); Intent intent = new Intent(AutoBrightnessController.ACTION_AUTO_BRIGHTNESS_CHANGED); intent.putExtra(AutoBrightnessController.EXTRA_BRIGHTNESS, (Integer) mScreenAutoBrightness); intent.putExtra(AutoBrightnessController.EXTRA_LUX, (Float) mAmbientLux); // ???? UserHandle user = (UserHandle) XposedHelpers.getStaticObjectField(UserHandle.class, "ALL"); mContext.sendBroadcastAsUser(intent, user); } }); }