List of usage examples for android.app PendingIntent getService
public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, @Flags int flags)
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
/** * Updates the stop button.//from ww w . j a v a2 s.c o m * * @param context the context * @param remoteViews the remote views * @param isRecording true if recording */ private static void updateStopButton(Context context, RemoteViews remoteViews, boolean isRecording) { remoteViews.setImageViewResource(R.id.track_widget_stop_button, isRecording ? R.drawable.button_stop : R.drawable.ic_button_stop_disabled); remoteViews.setBoolean(R.id.track_widget_stop_button, "setEnabled", isRecording); if (isRecording) { Intent intent = new Intent(context, ControlRecordingService.class) .setAction(context.getString(R.string.track_action_end)); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.track_widget_stop_button, pendingIntent); } }
From source file:at.vcity.androidimsocket.services.IMService.java
@Override public void onDestroy() { try {// w w w. java 2s .c o m unregisterReceiver(alarmReceiver); } catch (IllegalArgumentException e) { } AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, IMService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.cancel(pintent); Log.i("IMService is being destroyed", "..."); // super.onDestroy(); }
From source file:com.av.remusic.service.MediaService.java
@Override public void onCreate() { if (D)/*from ww w . j av a2s . co m*/ Log.d(TAG, "Creating service"); super.onCreate(); mGetUrlThread.start(); mLrcThread.start(); mProxy = new MediaPlayerProxy(this); mProxy.init(); mProxy.start(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // 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 MultiPlayer(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); filter.addAction(TRY_GET_TRACKINFO); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(LOCK_SCREEN); filter.addAction(SEND_PROGRESS); filter.addAction(SETQUEUE); // 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, MediaService.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:com.matthewmitchell.peercoin_android_wallet.WalletApplication.java
public void scheduleStartBlockchainService() { final WalletApplication wa = this; this.setOnLoadedCallback(new Runnable() { @Override//from w ww . ja v a 2 s.c o m public void run() { final long lastUsedAgo = config.getLastUsedAgo(); // apply some backoff final long alarmInterval; if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS) alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES; else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS) alarmInterval = AlarmManager.INTERVAL_HALF_DAY; else alarmInterval = AlarmManager.INTERVAL_DAY; log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes", lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS); assertTrue(config != null); final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(wa, 0, new Intent(wa, BlockchainServiceImpl.class), 0); alarmManager.cancel(alarmIntent); // workaround for no inexact set() before KitKat final long now = System.currentTimeMillis(); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY, alarmIntent); } }); }
From source file:com.lambdasoup.quickfit.alarm.AlarmService.java
/** * Replaces the notification for alarms with a notification about a single workout. * <p>/*from www . j ava 2 s .c om*/ * Relies on the caller to position the cursor on the desired row and to close the cursor. * * @param cursor Cursor to read the workout data from * @param cancelIntent Pending intent to pass on to the content intent, allowing its receiver to * execute it (update notification state in db to the fact that the notification * is now cancelled) */ @WorkerThread private @NonNull NotificationCompat.Builder notifySingleEvent(@NonNull Cursor cursor, PendingIntent cancelIntent) { NotificationCompat.Builder notification = new NotificationCompat.Builder(this); FitActivity fitActivity = FitActivity .fromKey(cursor.getString(cursor.getColumnIndex(WorkoutEntry.ACTIVITY_TYPE)), getResources()); String label = ""; if (!cursor.isNull(cursor.getColumnIndex(WorkoutEntry.LABEL))) { label = cursor.getString(cursor.getColumnIndex(WorkoutEntry.LABEL)); } int durationMinutes = cursor.getInt(cursor.getColumnIndex(WorkoutEntry.DURATION_MINUTES)); String title = getString(R.string.notification_alarm_title_single, fitActivity.displayName); String formattedMinutes = String.format( getResources().getQuantityString(R.plurals.duration_mins_format, durationMinutes), durationMinutes); String content = getString(R.string.notification_alarm_content_single, formattedMinutes, label); notification.setContentTitle(title); notification.setContentText(content); long workoutId = cursor.getLong(cursor.getColumnIndex(WorkoutEntry.WORKOUT_ID)); Intent workoutIntent = new Intent(getApplicationContext(), WorkoutListActivity.class); workoutIntent.putExtra(WorkoutListActivity.EXTRA_SHOW_WORKOUT_ID, workoutId); workoutIntent.putExtra(WorkoutListActivity.EXTRA_NOTIFICATIONS_CANCEL_INTENT, cancelIntent); PendingIntent activityIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(workoutIntent) .getPendingIntent(Constants.PENDING_INTENT_WORKOUT_LIST, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(activityIntent);// open workout list, scroll to workout long scheduleId = cursor.getLong(cursor.getColumnIndex(WorkoutEntry.SCHEDULE_ID)); PendingIntent didItIntent = PendingIntent.getService(getApplicationContext(), Constants.PENDING_INTENT_DID_IT, getIntentOnDidIt(getApplicationContext(), scheduleId, workoutId), PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.ic_done_white_24dp, getString(R.string.notification_action_did_it), didItIntent); PendingIntent snoozeIntent = PendingIntent.getService(getApplicationContext(), Constants.PENDING_INTENT_SNOOZE, AlarmService.getIntentOnSnooze(this, scheduleId), PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.ic_alarm_white_24dp, getString(R.string.notification_action_remind_me_later), snoozeIntent); return notification; }
From source file:arun.com.chromer.browsing.customtabs.CustomTabs.java
private void prepareCopyLink() { final Intent clipboardIntent = new Intent(activity, CopyToClipboardService.class); clipboardIntent.putExtra(EXTRA_KEY_ORIGINAL_URL, url); final PendingIntent serviceIntentPending = PendingIntent.getService(activity, 0, clipboardIntent, FLAG_UPDATE_CURRENT);// w ww . j ava 2 s. c om builder.addMenuItem(activity.getString(R.string.copy_link), serviceIntentPending); }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private PendingIntent getGeofencesPendingIntent(Context context) { Intent intent = new Intent(ACTION_GEODEFENCE_TRIGGER, null, context, LocationMuteService.class); return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
void startOneBootAlarm() { if (oneBootIntent != null) { alarmManager.cancel(oneBootIntent); //return; }/*from w w w. jav a2 s .com*/ oneBootIntent = null; String bootParameter = readBootParameter(1); Log.i("ALARM_SET", "got 1 boot parameters " + (bootParameter == null ? "nothing" : bootParameter)); if (bootParameter == null) return; int idx = bootParameter.indexOf("-"); if (idx < 0) return; long init_wait = Long.parseLong(bootParameter.substring(0, idx)); if (init_wait < 10000) { long on_time = Long.parseLong(bootParameter.substring(idx + 1)); sendCommand("M5-" + new DecimalFormat("00").format(on_time / 60000)); return; } Intent jIntent = new Intent(this, ConnectDaemonService.class); //M1-00 (cool) or M1-01 (warm) jIntent.setAction(ALARM_1BOOT); jIntent.putExtra(ConnectDaemonService.ALARM_DONE, ALARM_1BOOT); jIntent.putExtra(ConnectDaemonService.ALARM_1BOOT, bootParameter.substring(idx + 1)); oneBootIntent = PendingIntent.getService(this, ++boot1AlarmRequestId % 10 + 150, jIntent, PendingIntent.FLAG_ONE_SHOT); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + init_wait, oneBootIntent); Log.i("ALARM_SET", "to start one boot in " + init_wait / 60000); //startScheduledJobs(); }
From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java
/** * Background updates show ON or OFF// w w w .j a v a 2 s. c o m */ private void showAlert(String Message, String Title, final int alertCode) { final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false); dialog.setContentView(R.layout.alert_dialog_main); final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title); final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg); final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt); Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn); Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn); alertTitle.setText(Title); alertMsg.setText(Message); alertEditTxt.setVisibility(View.GONE); if (alertCode == 0 || alertCode == UPDATE_INT || alertCode == 7) { cancelBtn.setVisibility(View.VISIBLE); } else { cancelBtn.setVisibility(View.GONE); } cancelBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (alertCode == 7) { backUpdateToggle.setChecked(true); editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, true); editor.commit(); } } }); okBtn.setOnClickListener(new OnClickListener() { @SuppressWarnings("unused") @Override public void onClick(View v) { dialog.dismiss(); if (alertCode == 3 || alertCode == 4) { session.logoutUser(getActivity()); Intent i = new Intent(getActivity(), Login.class); startActivity(i); getActivity().finish(); } else if (alertCode == 0) { deactivateAcc(); } else if (alertCode == UPDATE_INT) { getActivity().finish(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.gpstracker.pro")); startActivity(intent); } else if (alertCode == 7) { backUpdateToggle.setChecked(false); editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, false); editor.commit(); AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); Calendar cal = Calendar.getInstance(); Intent intent2 = new Intent(getActivity(), BackgroundService.class); PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0); if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) { alarm.cancel(pintent); } } } }); dialog.show(); }
From source file:com.jasonmheim.rollout.station.CoreContentProvider.java
private PendingIntent getActionSettingIntent(int action) { Uri data = Constants.STATION_URI.buildUpon() // TODO: Don't use update keys for query param names .appendQueryParameter(UPDATE_KEY_ACTION, Integer.toString(action)).build(); Intent intent = new Intent(getContext(), ActionIntentService.class); intent.setData(data);/*from w w w. j a v a2 s . c o m*/ PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return pendingIntent; }