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:at.vcity.androidimsocket.services.IMService.java
public void authenticationResult(Object... args) { this.authenticatedUser = true; try {/* w ww . jav a 2s .c o m*/ JSONObject param = new JSONObject(args[0].toString()); String result = param.getString("result"); if (result.equals(NetworkCommand.SUCCESSFUL)) { //currentUserId=param.getString("userId"); FriendInfo f = new FriendInfo(); f.userName = username; f.userId = param.getString("userId"); Chatting.setCurrentUser(f); // getFriendList(); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, IMService.class); intent.putExtra("myToken", socketOperator.getToken()); intent.putExtra("username", username); intent.putExtra("password", password); PendingIntent pintent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + WAKE_TIME_PERIOD, WAKE_TIME_PERIOD, pintent); Intent loginintent = new Intent(TRY_LOGIN); loginintent.putExtra("AUTHENTICATION_RESULT", NetworkCommand.SUCCESSFUL); sendBroadcast(loginintent); // Start heartbeat heartIsBeating = true; startHeartbeat(); } else { Toast.makeText(this, "Wrong user name", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { } ; }
From source file:com.android.managedprovisioning.DeviceOwnerProvisioningService.java
private void setTimeAndTimezone(String timeZone, long localTime) { try {//from w w w .j a v a2 s . c o m final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (timeZone != null) { if (DEBUG) ProvisionLogger.logd("Setting time zone to " + timeZone); am.setTimeZone(timeZone); } if (localTime > 0) { if (DEBUG) ProvisionLogger.logd("Setting time to " + localTime); am.setTime(localTime); } } catch (Exception e) { ProvisionLogger.loge("Alarm manager failed to set the system time/timezone."); // Do not stop provisioning process, but ignore this error. } }
From source file:com.naman14.timber.musicplayer.MusicService.java
@Override public void onCreate() { if (D)//from w w w . j a va2s .c o m Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setUpMediaSession(); } mPreferences = getSharedPreferences("Service", 0); // mCardId = getCardId(); // registerExternalStorageListener(); mPlayer = new MultiPlayer2(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); // getContentResolver().registerContentObserver( // MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); // getContentResolver().registerContentObserver( // MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); // reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:de.domjos.schooltools.activities.MainActivity.java
private void initServices() { try {/* ww w . java 2 s .c o m*/ if (MainActivity.globals.getUserSettings().isNotificationsShown()) { // init Memory Service Intent intent = new Intent(this.getApplicationContext(), MemoryService.class); PendingIntent pendingIntent1 = PendingIntent.getService(this.getApplicationContext(), 0, intent, 0); // init frequently AlarmManager alarmManager1 = (AlarmManager) this.getApplicationContext() .getSystemService(Context.ALARM_SERVICE); long frequency = 8 * 60 * 60 * 1000; assert alarmManager1 != null; alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(), frequency, pendingIntent1); } } catch (Exception ex) { Helper.printException(this.getApplicationContext(), ex); } }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void showCollapsedNotificationWithNext(final Context context, String title, String text, Long nextBroadcastTime) { LogUtils.d(TAG, "showCollapsedNotificationWithNext nextBroadcastTime: %d", nextBroadcastTime); Intent activityIntent = new Intent(context, DeskClock.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX); PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); showCollapsedNotification(context, title, text, NotificationCompat.PRIORITY_HIGH, pendingActivityIntent, IN_USE_NOTIFICATION_ID, false); if (nextBroadcastTime == null) { return;/* w ww . j a v a 2 s .c om*/ } Intent nextBroadcast = new Intent(); nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW); PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } else { alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
/** * Remove the alarm for the quarter hour update. * * @param context The context in which the PendingIntent was started to perform the broadcast. */// ww w . j a v a 2s .co m public void cancelAlarmOnQuarterHour(Context context) { if (context != null) { PendingIntent quarterlyIntent = getOnQuarterHourPendingIntent(context); ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).cancel(quarterlyIntent); } }
From source file:org.mariotaku.twidere.service.TwidereService.java
@Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mAsyncTaskManager = ((TwidereApplication) getApplication()).getAsyncTaskManager(); mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); final Intent refresh_intent = new Intent(BROADCAST_AUTO_REFRESH); mPendingRefreshIntent = PendingIntent.getBroadcast(this, 0, refresh_intent, 0); final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED); filter.addAction(BROADCAST_NOTIFICATION_CLEARED); filter.addAction(BROADCAST_AUTO_REFRESH); registerReceiver(mStateReceiver, filter); startAutoRefresh();//from ww w . j a v a 2 s. c o m }
From source file:com.embeddedlog.LightUpDroid.DeskClock.java
private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); return true; case R.id.menu_item_help: Intent i = item.getIntent();/*from w w w .j a v a 2s . c o m*/ if (i != null) { try { startActivity(i); } catch (ActivityNotFoundException e) { // No activity found to match the intent - ignore } } return true; case R.id.menu_item_night_mode: startActivity(new Intent(DeskClock.this, ScreensaverActivity.class)); case R.id.menu_item_sync_lightuppi: // TODO: update LightUpPiSync to actually sync alarms and then update this bit return true; case R.id.menu_item_push_to_lightuppi: // TODO: update LightUpPiSync to actually push alarms and then update this bit return true; case R.id.menu_item_push_to_phone: // TODO: update LightUpPiSync to actually push alarms and then update this bit String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX; new LightUpPiSync(this, correctString).syncPushToPhone(); return true; case R.id.menu_item_reset_db: // Delete the database ContentResolver cr = this.getContentResolver(); cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null); // Restart the app to repopulate db with default and recreate activities. Intent mStartActivity = new Intent(this, DeskClock.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); return true; default: break; } return true; }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static void clearUpdateAlarm(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmintent = new Intent(context, AlarmReceiver.class); alarmintent.setAction(AlarmReceiver.ALARM_UPDATE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, 0, alarmintent, 0); MyApp.LogDebug(LOG_TAG, "clear update alarm"); alarmManager.cancel(pendingintent);/*from w ww. j av a 2 s . c o m*/ }
From source file:com.tvs.signaltracker.MainScreen.java
@Override protected void onResume() { super.onResume(); CleanUp();//from www . j a va 2 s .c om try { if (STService.Opened == false) { Intent myIntent = new Intent(MainScreen.this, STService.class); PendingIntent pendingIntent = PendingIntent.getService(MainScreen.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) MainScreen.this.getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 1); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } } catch (Exception e) { Log.e("SignalTracker::onResume(MainScreen)", "Erro ao iniciar servio: " + e.getMessage()); } if (!CommonHandler.ServiceRunning) CommonHandler.LoadLists(); setUpMap(); InitUp(); }