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.njlabs.amrita.aid.landing.Landing.java
@SuppressLint("ShortAlarm") @Override// w w w . j ava 2s .c o m public void init(Bundle savedInstanceState) { setupLayout(R.layout.activity_landing, "Amrita Info Desk"); toolbar.setBackgroundColor(getResources().getColor(R.color.white)); setRecentHeaderColor(getResources().getColor(R.color.white)); checkForUpdates(); AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this) .withHeaderBackground(R.drawable.header) .addProfiles(new ProfileDrawerItem().withName("Amrita Info Desk") .withEmail("Version " + BuildConfig.VERSION_NAME).setSelectable(false)) .withSelectionListEnabledForSingleProfile(false).build(); headerResult.getHeaderBackgroundView().setColorFilter(Color.rgb(170, 170, 170), android.graphics.PorterDuff.Mode.MULTIPLY); Drawer result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult) .addDrawerItems( new PrimaryDrawerItem().withName("Home").withIcon(R.drawable.ic_action_home) .withCheckable(false), new PrimaryDrawerItem() .withName("News").withIcon(R.drawable.ic_action_speaker_notes).withCheckable(false), new DividerDrawerItem(), new PrimaryDrawerItem().withName("About the app").withIcon(R.drawable.ic_action_info) .withCheckable(false), new PrimaryDrawerItem().withName("Invite").withIcon(R.drawable.ic_action_info) .withCheckable(false), new PrimaryDrawerItem().withName("Settings").withIcon(R.drawable.ic_action_settings) .withCheckable(false)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { switch (position) { case 1: startActivity(new Intent(baseContext, NewsActivity.class)); break; case 3: startActivity(new Intent(baseContext, App.class)); break; case 4: Intent intent = new AppInviteInvitation.IntentBuilder("Invite users") .setMessage("Spread the word to fellow Amrititans") .setCallToActionText("Invite").build(); startActivityForResult(intent, 211); break; case 5: startActivity(new Intent(baseContext, SettingsActivity.class)); break; } return false; } }).withCloseOnClick(true).build(); setupGrid(); File aumsCookieFile = new File(getApplicationContext().getFilesDir().getParent() + "/shared_prefs/" + PersistentCookieStore.AUMS_COOKIE_PREFS + ".xml"); if (aumsCookieFile.exists()) { aumsCookieFile.delete(); } File gpmsCookieFile = new File(getApplicationContext().getFilesDir().getParent() + "/shared_prefs/" + PersistentCookieStore.GPMS_COOKIE_PREFS + ".xml"); if (gpmsCookieFile.exists()) { gpmsCookieFile.delete(); } AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE); alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 60 * 60 * 6), PendingIntent.getService(this, 0, new Intent(this, NewsUpdateService.class), 0)); startService(new Intent(baseContext, NewsUpdateService.class)); }
From source file:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.java
private void startNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout); contentView.setImageViewResource(R.id.notification_icon, R.drawable.notification_icon); contentView.setTextViewText(R.id.notification_title, getString(R.string.notification_title)); contentView.setTextViewText(R.id.notification_text, urlToStream); if (isPreparing) { contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.notification_playback_loading); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)); } else if (isStreamError) { contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.notification_playback_error); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0)); } else if (isPlaying) { contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.stop_button); PendingIntent stopIntentPending = PendingIntent.getService(this, 0, new Intent(MainActivity.STOP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, stopIntentPending); } else {//from ww w . j a v a2s .c om contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.play_button); Intent playIntent = new Intent(MainActivity.PLAY_INTENT); playIntent.putExtra(MainActivity.URL_EXTRA, urlToStream); PendingIntent playIntentPending = PendingIntent.getService(this, 0, playIntent, PendingIntent.FLAG_CANCEL_CURRENT); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, playIntentPending); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); contentView.setOnClickPendingIntent(R.id.notification_layout, contentIntent); PendingIntent killIntentPending = PendingIntent.getService(this, 0, new Intent(MainActivity.KILL_SERVICE_INTENT), 0); contentView.setOnClickPendingIntent(R.id.close_notification_icon, killIntentPending); builder.setContent(contentView); builder.setSmallIcon(R.drawable.notification_icon); builder.setAutoCancel(false); startForeground(NOTIFICATION_ID, builder.build()); }
From source file:com.android.deskclock.data.TimerNotificationBuilderPreN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final long remainingTime = timer.getRemainingTime(); // Generate some descriptive text, a title, and some actions based on timer states. final String contentText; final String contentTitle; @DrawableRes/* ww w. j a v a 2 s.c o m*/ int firstActionIconId, secondActionIconId = 0; @StringRes int firstActionTitleId, secondActionTitleId = 0; Intent firstActionIntent, secondActionIntent = null; if (unexpired.size() == 1) { contentText = formatElapsedTimeUntilExpiry(context, remainingTime); if (timer.isRunning()) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { contentTitle = context.getString(R.string.timer_notification_label); } else { contentTitle = timer.getLabel(); } firstActionIconId = R.drawable.ic_pause_24dp; firstActionTitleId = R.string.timer_pause; firstActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); secondActionIconId = R.drawable.ic_add_24dp; secondActionTitleId = R.string.timer_plus_1_min; secondActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); } else { // Single timer is paused. contentTitle = context.getString(R.string.timer_paused); firstActionIconId = R.drawable.ic_start_24dp; firstActionTitleId = R.string.sw_resume_button; firstActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); secondActionIconId = R.drawable.ic_reset_24dp; secondActionTitleId = R.string.sw_reset_button; secondActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); } } else { if (timer.isRunning()) { // At least one timer is running. final String timeRemaining = formatElapsedTimeUntilExpiry(context, remainingTime); contentText = context.getString(R.string.next_timer_notif, timeRemaining); contentTitle = context.getString(R.string.timers_in_use, unexpired.size()); } else { // All timers are paused. contentText = context.getString(R.string.all_timers_stopped_notif); contentTitle = context.getString(R.string.timers_stopped, unexpired.size()); } firstActionIconId = R.drawable.ic_reset_24dp; firstActionTitleId = R.string.timer_reset_all; firstActionIntent = TimerService.createResetUnexpiredTimersIntent(context); } // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true) .setLocalOnly(true).setShowWhen(false).setAutoCancel(false).setContentText(contentText) .setContentTitle(contentTitle).setContentIntent(pendingShowApp) .setSmallIcon(R.drawable.stat_notify_timer).setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setColor(ContextCompat.getColor(context, R.color.default_background)); final PendingIntent action1 = Utils.pendingServiceIntent(context, firstActionIntent); final String action1Title = context.getString(firstActionTitleId); builder.addAction(firstActionIconId, action1Title, action1); if (secondActionIntent != null) { final PendingIntent action2 = Utils.pendingServiceIntent(context, secondActionIntent); final String action2Title = context.getString(secondActionTitleId); builder.addAction(secondActionIconId, action2Title, action2); } final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent updateNotification = TimerService.createUpdateNotificationIntent(context); if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) { // Schedule a callback to update the time-sensitive information of the running timer. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS; final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange; TimerModel.schedulePendingIntent(am, triggerTime, pi); } else { // Cancel the update notification callback. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE); if (pi != null) { am.cancel(pi); pi.cancel(); } } return builder.build(); }
From source file:com.actinarium.rhythm.control.RhythmNotificationService.java
private NotificationCompat.Builder makeCommonNotification(String text) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.arl_rhythm).setCategory(NotificationCompat.CATEGORY_SERVICE) .setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(false).setShowWhen(false) .setContentText(text).setStyle(new NotificationCompat.BigTextStyle().bigText(text)); // Old androids throw an exception when the notification doesn't have content intent if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { Intent contentAction = new Intent(this, RhythmNotificationService.class); contentAction.setAction(ACTION_NEXT_OVERLAY); PendingIntent piContentAction = PendingIntent.getService(this, 0, contentAction, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(piContentAction); }//from w w w. j av a 2s. c o m return builder; }
From source file:com.gecq.musicwave.player.NotificationHelper.java
/** * @param which Which {@link PendingIntent} to return * @return A {@link PendingIntent} ready to control playback */// w w w . j a v a2 s .c o m private final PendingIntent retreivePlaybackActions(final int which) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(mService, PlayerService.class); switch (which) { case 1: // Play and pause action = new Intent(PlayerService.TOGGLEPAUSE_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 1, action, 0); return pendingIntent; case 2: // Skip tracks action = new Intent(PlayerService.NEXT_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 2, action, 0); return pendingIntent; case 3: // Previous tracks action = new Intent(PlayerService.PREVIOUS_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 3, action, 0); return pendingIntent; case 4: // Stop and collapse the notification action = new Intent(PlayerService.STOP_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 4, action, 0); return pendingIntent; default: break; } return null; }
From source file:com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialIntentService.java
private NotificationCompat.Builder recreateBuilderWithBigPictureStyle() { // Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on // building this notification, check StandaloneMainActivity.java): // 0. Get your data // 1. Build the BIG_PICTURE_STYLE // 2. Set up main Intent for notification // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification // 4. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase .getBigPictureStyleData();//from w w w . j a va 2 s. com // 1. Build the BIG_PICTURE_STYLE BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle() .bigPicture( BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage())) .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle()) .setSummaryText(bigPictureStyleSocialAppData.getSummaryText()); // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly // from the notification without entering the app. String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel).setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build(); Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class); replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT); PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0); // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the // lower portion of the Notification for easy action (only possible for one action). final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender() .setHintDisplayActionInline(true).setHintLaunchesActivity(false); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput) // Add WearableExtender to enable inline actions .extend(inlineActionForWear2).build(); // 4. Build and issue the notification NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // Build notification notificationCompatBuilder.setStyle(bigPictureStyle) .setContentTitle(bigPictureStyleSocialAppData.getContentTitle()) .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent).setColor(getResources().getColor(R.color.colorPrimary)) .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL) .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PRIVATE) .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true)); for (String name : bigPictureStyleSocialAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } return notificationCompatBuilder; }
From source file:com.boko.vimusic.NotificationHelper.java
/** * @param which// w w w . j a v a 2s .co m * Which {@link PendingIntent} to return * @return A {@link PendingIntent} ready to control playback */ private final PendingIntent retreivePlaybackActions(final int which) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(mService, MediaPlaybackService.class); switch (which) { case 1: // Play and pause action = new Intent(MediaPlaybackService.ACTION_PLAYER_TOGGLEPAUSE); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 1, action, 0); return pendingIntent; case 2: // Skip tracks action = new Intent(MediaPlaybackService.ACTION_PLAYER_NEXT); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 2, action, 0); return pendingIntent; case 3: // Previous tracks action = new Intent(MediaPlaybackService.ACTION_PLAYER_PREVIOUS); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 3, action, 0); return pendingIntent; case 4: // Stop and collapse the notification action = new Intent(MediaPlaybackService.ACTION_PLAYER_STOP); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 4, action, 0); return pendingIntent; default: break; } return null; }
From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java
/** * Updates button to start/stop recording. * // w ww . j av a 2 s. co m * @param remoteViews the remote views * @param action the action */ private void updateButton(RemoteViews remoteViews, String action) { boolean isRecording = trackStartedBroadcastAction.equals(action); remoteViews.setViewVisibility(R.id.track_widget_record_button, isRecording ? View.GONE : View.VISIBLE); remoteViews.setViewVisibility(R.id.track_widget_stop_button, isRecording ? View.VISIBLE : View.INVISIBLE); Intent intent = new Intent(context, ControlRecordingService.class).setAction( context.getString(isRecording ? R.string.track_action_end : R.string.track_action_start)); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent( isRecording ? R.id.track_widget_stop_button : R.id.track_widget_record_button, pendingIntent); }
From source file:de.schildbach.wallet.service.BlockchainService.java
public static void scheduleStart(final WalletApplication application) { final Configuration config = application.getConfiguration(); 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/*from w ww . ja v a 2 s . c o m*/ 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); final AlarmManager alarmManager = (AlarmManager) application.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(application, 0, new Intent(application, BlockchainService.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.tvs.signaltracker.STService.java
private void UpdateData(boolean fromGPS) { UpdateWiFi();//from w w w .j a va 2s . c o m if (CommonHandler.Signal > -1 & CommonHandler.Signal <= 31 & !CommonHandler.Operator.trim().isEmpty()) { if (Utils.isBetterLocation(CommonHandler.GPSLocation, CommonHandler.NetLocation)) CommonHandler.AddSignal(CommonHandler.GPSLocation.getLatitude(), CommonHandler.GPSLocation.getLongitude(), CommonHandler.Signal, CommonHandler.Weight, true); else CommonHandler.AddSignal(CommonHandler.NetLocation.getLatitude(), CommonHandler.NetLocation.getLongitude(), CommonHandler.Signal, 0.2f, false); if ((CommonHandler.ServiceMode == 1 || CommonHandler.ServiceMode == 3) & fromGPS) { // LightModes - dados atualizados. Ento parar o servio e agendar ele pra LightModeTime * 60 Log.i("SignalTracker::LightMode", "Location Acquired, scheduling next search for " + (CommonHandler.LightModeDelayTime * 60) + " seconds ahead."); CommonHandler.KillService = true; StopWorks(); Intent myIntent = new Intent(STService.this, STService.class); PendingIntent pendingIntent = PendingIntent.getService(STService.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) STService.this.getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, CommonHandler.LightModeDelayTime * 60); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); this.stopSelf(); } else if (CommonHandler.ServiceRunning) showServiceNotification(); } }