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:com.remdo.app.MainActivity.java
/** * Anables geopositioning service with configured minutes span in Services database *///from w ww. j a v a 2 s . com private void enableGeopositioning() { mGeoInterval = dm.getServcieMinutes("Geo"); long milisegundos = mGeoInterval * 60 * 1000; Intent intent = new Intent(this, GeopositioningService.class); pendingGeoIntent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 10); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), milisegundos, pendingGeoIntent); Toast.makeText(this, getString(R.string.started_geo_service), Toast.LENGTH_LONG).show(); }
From source file:com.granita.tasks.notification.NotificationActionUtils.java
/** * Creates and displays an Undo notification for the specified {@link NotificationAction}. *//* ww w. ja va2 s . com*/ public static void createUndoNotification(final Context context, NotificationAction action) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(action.getActionTextResId() )); builder.setSmallIcon(R.drawable.ic_notification); builder.setWhen(action.getWhen()); // disable sound & vibration builder.setDefaults(0); final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification); undoView.setTextViewText(R.id.description_text, context.getString(action.mActionTextResId)); final String packageName = context.getPackageName(); final Intent clickIntent = new Intent(ACTION_UNDO); clickIntent.setPackage(packageName); putNotificationActionExtra(clickIntent, action); final PendingIntent clickPendingIntent = PendingIntent.getService(context, action.getNotificationId(), clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent); builder.setContent(undoView); // When the notification is cleared, we perform the destructive action final Intent deleteIntent = new Intent(ACTION_DESTRUCT); deleteIntent.setPackage(packageName); putNotificationActionExtra(deleteIntent, action); final PendingIntent deletePendingIntent = PendingIntent.getService(context, action.getNotificationId(), deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deletePendingIntent); final Notification notification = builder.build(); final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(action.getNotificationId(), notification); sUndoNotifications.put(action.getNotificationId(), action); sNotificationTimestamps.put(action.getNotificationId(), action.mWhen); }
From source file:at.alladin.rmbt.android.test.RMBTLoopService.java
@Override public void onCreate() { Log.d(TAG, "created"); super.onCreate(); partialWakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RMBTLoopWakeLock"); partialWakeLock.acquire();//from ww w.ja v a2 s .com alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); readConfig(); geoLocation = new LocalGeoLocation(this); geoLocation.start(); notificationBuilder = createNotificationBuilder(); startForeground(NotificationIDs.LOOP_ACTIVE, notificationBuilder.build()); final IntentFilter actionFilter = new IntentFilter(RMBTService.BROADCAST_TEST_FINISHED); actionFilter.addAction(RMBTService.BROADCAST_TEST_ABORTED); registerReceiver(receiver, actionFilter); final IntentFilter rmbtTaskActionFilter = new IntentFilter(RMBTTask.BROADCAST_TEST_START); registerReceiver(rmbtTaskReceiver, rmbtTaskActionFilter); final Intent alarmIntent = new Intent(ACTION_ALARM, null, this, getClass()); alarm = PendingIntent.getService(this, 0, alarmIntent, 0); if (ConfigHelper.isLoopModeWakeLock(this)) { Log.d(TAG, "using dimWakeLock"); dimWakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "RMBTLoopDimWakeLock"); dimWakeLock.acquire(); final Intent wakeupAlarmIntent = new Intent(ACTION_WAKEUP_ALARM, null, this, getClass()); wakeupAlarm = PendingIntent.getService(this, 0, wakeupAlarmIntent, 0); final long now = SystemClock.elapsedRealtime(); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + 10000, 10000, wakeupAlarm); } bindService(new Intent(getApplicationContext(), RMBTService.class), this, BIND_AUTO_CREATE); }
From source file:com.razza.apps.iosched.service.SessionAlarmService.java
public void scheduleFeedbackAlarm(final long sessionEnd, final long alarmOffset, final String sessionTitle) { // By default, feedback alarms fire 5 minutes before session end time. If alarm offset is // provided, alarm is set to go off that much time from now (useful for testing). long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionEnd - MILLI_FIVE_MINUTES; } else {//w w w . ja va 2 s . co m alarmTime = UIUtils.getCurrentTime(this) + alarmOffset; } LogUtils.LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'"); LogUtils.LOGD(TAG, " -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString()); LogUtils.LOGD(TAG, " -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent feedbackIntent = new Intent(ACTION_NOTIFY_SESSION_FEEDBACK, null, this, SessionAlarmService.class); PendingIntent pi = PendingIntent.getService(this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.stasbar.knowyourself.alarms.AlarmNotifications.java
public static void showSnoozeNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(context.getString(R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false).setSortKey(createSortKey(instance)) .setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true); if (Utils.isNOrLater()) { notification.setGroup(UPCOMING_GROUP_KEY); }/* w ww . j a v a 2 s . c om*/ // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); notification.addAction(R.drawable.ic_alarm_off_24dp, context.getString(R.string.alarm_alert_dismiss_text), PendingIntent.getService(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(instance.hashCode(), notification.build()); updateAlarmGroupNotification(context); }
From source file:com.example.android.xyztouristattractions.service.UtilityService.java
/** * Called when a location update is requested */// ww w . j a v a 2 s . c o m private void requestLocationInternal() { Log.v(TAG, ACTION_REQUEST_LOCATION); GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect(Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { Intent locationUpdatedIntent = new Intent(this, UtilityService.class); locationUpdatedIntent.setAction(ACTION_LOCATION_UPDATED); // Send last known location out first if available Location location = FusedLocationApi.getLastLocation(googleApiClient); if (location != null) { Intent lastLocationIntent = new Intent(locationUpdatedIntent); lastLocationIntent.putExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED, location); startService(lastLocationIntent); } // Request new location LocationRequest mLocationRequest = new LocationRequest() .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); FusedLocationApi.requestLocationUpdates(googleApiClient, mLocationRequest, PendingIntent.getService(this, 0, locationUpdatedIntent, 0)); googleApiClient.disconnect(); } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } }
From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java
public void scheduleFeedbackAlarm(final long sessionEnd, final long alarmOffset, final String sessionTitle) { // By default, feedback alarms fire 5 minutes before session end time. If alarm offset is // provided, alarm is set to go off that much time from now (useful for testing). long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionEnd - MILLI_FIVE_MINUTES; } else {/* w ww . j a v a2s.com*/ alarmTime = UIUtils.getCurrentTime(this) + alarmOffset; } LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'"); LOGD(TAG, " -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString()); LOGD(TAG, " -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent feedbackIntent = new Intent(ACTION_NOTIFY_SESSION_FEEDBACK, null, this, SessionAlarmService.class); PendingIntent pi = PendingIntent.getService(this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.example.activitydemo.app.service.GameService.java
public void removeActivityUpdates() { if (mRecognitionPendingIntent == null) { mRecognitionPendingIntent = PendingIntent.getService(this, 0, new Intent(this, RecognitionIntentService.class), PendingIntent.FLAG_UPDATE_CURRENT); }//w w w. jav a2s.c om if (mClient != null && mClient.isConnected()) { ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(mClient, mRecognitionPendingIntent); mRecognitionPendingIntent.cancel(); } mRecognitionPendingIntent.cancel(); }
From source file:com.hodor.company.areminder.ui.MainActivity.java
private void registerAlarmManager(long duration) { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(ACTION_SHOW_ALARM, null, this, TimerService.class); intent.putExtra("category", category.ordinal()); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); long time = System.currentTimeMillis() + duration; alarmManager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent); }
From source file:com.android.dialer.calllog.DefaultVoicemailNotifier.java
/** Creates a pending intent that marks all new voicemails as old. */ private PendingIntent createMarkNewVoicemailsAsOldIntent() { Intent intent = new Intent(mContext, CallLogNotificationsService.class); intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD); return PendingIntent.getService(mContext, 0, intent, 0); }