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.syncedsynapse.kore2.service.NotificationService.java
private PendingIntent buildActionPendingIntent(int playerId, String action) { LogUtils.LOGD(TAG, "Build action: " + action); Intent intent = new Intent(this, IntentActionsService.class).setAction(action) .putExtra(IntentActionsService.EXTRA_PLAYER_ID, playerId); return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.kylemsguy.fishyfishes.MainActivity.java
private PendingIntent getGeofencePendingIntent() { Intent intent = new Intent(this, GeofenceService.class); // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when // calling addGeofences() and removeGeofences(). return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:br.com.bioscada.apps.biotracks.services.TrackRecordingService.java
@Override public void onCreate() { super.onCreate(); executorService = Executors.newSingleThreadExecutor(); context = this; myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); handler = new Handler(); myTracksLocationManager = new MyTracksLocationManager(this, handler.getLooper(), true); activityRecognitionPendingIntent = PendingIntent.getService(context, 0, new Intent(context, ActivityRecognitionIntentService.class), PendingIntent.FLAG_UPDATE_CURRENT); activityRecognitionClient = new ActivityRecognitionClient(context, activityRecognitionCallbacks, activityRecognitionFailedListener); try {//from w w w . j a v a 2 s .c om activityRecognitionClient.connect(); } catch (Exception e) { Log.d("BIOTRACKS", e.getMessage()); } splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory()); voiceSplitExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory()); voice1Executor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory()); voice2Executor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory()); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); // onSharedPreferenceChanged might not set recordingTrackId. recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; // Require voiceExecutor and splitExecutor to be created. sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null); handler.post(registerLocationRunnable); /* * Try to restart the previous recording track in case the service has been * restarted by the system, which can sometimes happen. */ Track track = myTracksProviderUtils.getTrack(recordingTrackId); if (track != null) { restartTrack(track); } else { if (isRecording()) { Log.w(TAG, "track is null, but recordingTrackId not -1L. " + recordingTrackId); updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true); } showNotification(false); } }
From source file:com.wojtechnology.sunami.TheBrain.java
private void setNotification(FireMixtape song) { if (mPlaying == null) { stopForeground(true);// w w w .j a v a 2 s . c o m return; } setMetadata(song); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Notification is created in setMetadata return; } if (mNotification == null || mNotificationView == null) { Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 1, notificationIntent, 0); mNotificationView = new RemoteViews(getPackageName(), R.layout.notification); mNotification = new Notification.Builder(this).setSmallIcon(R.mipmap.sunaminotif) .setContentIntent(pendingIntent).setContent(mNotificationView).build(); } Intent servicePlayIntent = new Intent(getApplicationContext(), TheBrain.class); servicePlayIntent.setAction(TheBrain.TOGGLE_PLAY); servicePlayIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingPlayIntent = PendingIntent.getService(mContext, 1, servicePlayIntent, 0); Intent serviceNextIntent = new Intent(getApplicationContext(), TheBrain.class); serviceNextIntent.setAction(TheBrain.PLAY_NEXT); serviceNextIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingNextIntent = PendingIntent.getService(mContext, 1, serviceNextIntent, 0); Intent serviceStopIntent = new Intent(getApplicationContext(), TheBrain.class); serviceStopIntent.setAction(TheBrain.PLAY_STOP); serviceStopIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingStopIntent = PendingIntent.getService(mContext, 1, serviceStopIntent, 0); mNotificationView.setTextViewText(R.id.notif_title, song.title); mNotificationView.setTextViewText(R.id.notif_artist, song.artist); mNotificationView.setOnClickPendingIntent(R.id.play_notif_button, pendingPlayIntent); mNotificationView.setOnClickPendingIntent(R.id.next_notif_button, pendingNextIntent); mNotificationView.setOnClickPendingIntent(R.id.close_notif_button, pendingStopIntent); setNotificationStatus(true); }
From source file:com.damageddev.myotaskerplugin.services.BackgroundService.java
private NotificationCompat.Builder buildConnectNotification() { Intent connectIntent = new Intent(ACTION_DISCONNECT); PendingIntent connectPendingIntent = PendingIntent.getService(this, 0, connectIntent, PendingIntent.FLAG_UPDATE_CURRENT); return new NotificationCompat.Builder(BackgroundService.this).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getString(R.string.myo_connected)).setOngoing(true) .addAction(R.drawable.ic_connect, getString(R.string.connect_to_myo), connectPendingIntent); }
From source file:com.androidinspain.deskclock.alarms.AlarmNotifications.java
static synchronized void showMissedNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying missed notification for alarm instance: " + instance.mId); String label = instance.mLabel; String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime()); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(context.getString(com.androidinspain.deskclock.R.string.alarm_missed_title)) .setContentText(instance.mLabel.isEmpty() ? alarmTime : context.getString(com.androidinspain.deskclock.R.string.alarm_missed_text, alarmTime, label))//from w w w . j av a 2 s.c om .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)) .setSortKey(createSortKey(instance)) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_alarm) .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true); if (Utils.isNOrLater()) { builder.setGroup(MISSED_GROUP_KEY); } final int id = instance.hashCode(); // Setup dismiss intent Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); builder.setDeleteIntent( PendingIntent.getService(context, id, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content intent Intent showAndDismiss = AlarmInstance.createIntent(context, AlarmStateManager.class, instance.mId); showAndDismiss.putExtra(EXTRA_NOTIFICATION_ID, id); showAndDismiss.setAction(AlarmStateManager.SHOW_AND_DISMISS_ALARM_ACTION); builder.setContentIntent( PendingIntent.getBroadcast(context, id, showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); final Notification notification = builder.build(); nm.notify(id, notification); updateMissedAlarmGroupNotification(context, -1, notification); }
From source file:com.klinker.android.twitter.activities.MainActivity.java
@Override public void onStart() { super.onStart(); MainActivity.isPopup = false;/*from w w w. j ava 2s .c o m*/ Log.v("talon_starting", "main activity starting"); sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0); // check for night mode switching int theme = AppSettings.getCurrentTheme(sharedPrefs); if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY) || sharedPrefs.getBoolean("launcher_frag_switch", false) || (theme != settings.theme && !settings.addonTheme)) { sharedPrefs.edit().putBoolean("launcher_frag_switch", false).putBoolean("dont_refresh", true).commit(); AppSettings.invalidate(); Log.v("talon_theme", "no action bar overlay found, recreating"); finish(); overridePendingTransition(0, 0); startActivity(getRestartIntent()); overridePendingTransition(0, 0); MainActivity.caughtstarting = true; // return so that it doesn't start the background refresh, that is what caused the dups. sharedPrefs.edit().putBoolean("dont_refresh_on_start", true).commit(); return; } else { sharedPrefs.edit().putBoolean("dont_refresh", false).putBoolean("should_refresh", true).commit(); } if (DrawerActivity.settings.pushNotifications) { if (!TalonPullNotificationService.isRunning) { context.startService(new Intent(context, TalonPullNotificationService.class)); } } else { context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE")); } // cancel the alarm to start the catchup service AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService(context, 236, new Intent(context, CatchupPull.class), 0); am.cancel(pendingIntent); // cancel the old one, then start the new one in 1 min // clear the pull unread sharedPrefs.edit().putInt("pull_unread", 0).commit(); // will only run when debugging new Handler().postDelayed(new Runnable() { @Override public void run() { NotificationUtils.sendTestNotification(MainActivity.this); } }, 1000); }
From source file:at.alladin.rmbt.android.test.RMBTLoopService.java
private NotificationCompat.Builder createNotificationBuilder() { final Resources res = getResources(); Intent notificationIntent = new Intent(getApplicationContext(), RMBTMainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent openAppIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_icon_loop) .setContentTitle(res.getText(R.string.loop_notification_title)) .setTicker(res.getText(R.string.loop_notification_ticker)).setContentIntent(openAppIntent); setNotificationText(builder);//from w w w . j a va 2s.c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (SHOW_DEV_BUTTONS) { final Intent stopIntent = new Intent(ACTION_STOP, null, getApplicationContext(), getClass()); final PendingIntent stopPIntent = PendingIntent.getService(getApplicationContext(), 0, stopIntent, 0); final Intent forceIntent = new Intent(ACTION_FORCE, null, getApplicationContext(), getClass()); final PendingIntent forcePIntent = PendingIntent.getService(getApplicationContext(), 0, forceIntent, 0); addActionToNotificationBuilder(builder, stopPIntent, forcePIntent); } } return builder; }
From source file:com.mylovemhz.simplay.MusicService.java
private void showNotification() { updateMetadata();//from ww w .j ava2 s . co m Track track; try { track = getCurrentTrack(); } catch (IllegalStateException e) { return; } Intent intent = new Intent(getApplicationContext(), MusicService.class); intent.setAction(ACTION_STOP); PendingIntent cancelIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0); final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle(builder); style.setMediaSession(getMediaSessionToken()); style.setShowCancelButton(true); style.setCancelButtonIntent(cancelIntent); style.setShowActionsInCompactView(1); builder.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS)); //0 if (!isPlaying()) { builder.addAction(generateAction(android.R.drawable.ic_media_play, "Play", ACTION_PLAY)); // 1 } else { builder.addAction(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE)); //1 } builder.addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT)); //2 builder.setSmallIcon(smallIcon).setContentTitle(track.getTitle()).setContentText(track.getArtist()) .setDeleteIntent(cancelIntent).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setStyle(style); if (!track.getArtworkUrl().isEmpty()) { try { Target artTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { builder.setLargeIcon(bitmap); publishNotification(builder); temporaryTargets.remove(this); } @Override public void onBitmapFailed(Drawable errorDrawable) { publishNotification(builder); temporaryTargets.remove(this); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; temporaryTargets.add(artTarget); Picasso.with(this).load(track.getArtworkUrl()).into(artTarget); } catch (IllegalArgumentException e) { //no artwork. Ignore. publishNotification(builder); } } else { publishNotification(builder); } }
From source file:edu.mit.media.funf.probe.Probe.java
private void updateInternalRequestsPendingIntent() { PendingIntent internalPendingIntent = PendingIntent.getService(this, 0, requestsIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Keep the pending intent valid, by having the alarm clock keep a reference to it AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE); manager.set(AlarmManager.RTC, System.currentTimeMillis() + FAR_IN_FUTURE_MILLIS, internalPendingIntent); }