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.actinarium.nagbox.service.NotificationHelper.java
/** * Make a new notification builder with common attributes already set. * * @param context context/*from w w w . j a va 2 s . c o m*/ * @param currentTime timestamp to display in the notification * @param dismissedTaskId ID of the task to dismiss with this notification, or {@link Task#NO_ID} to dismiss all * @return partially pre-configured notification builder */ private static NotificationCompat.Builder makeCommonBuilder(Context context, long currentTime, long dismissedTaskId) { // When notification is clicked, simply go to the app Intent primaryAction = new Intent(context, MainActivity.class); PendingIntent primaryActionPI = PendingIntent.getActivity(context, 0, primaryAction, PendingIntent.FLAG_UPDATE_CURRENT); // When notification is dismissed, tell the service to handle it properly Intent dismissAction = new Intent(context, NagboxService.class); dismissAction.setAction(NagboxService.ACTION_ON_NOTIFICATION_DISMISSED); dismissAction.putExtra(NagboxService.EXTRA_TASK_ID, dismissedTaskId); // Just as well, this pending intent needs a unique request code, otherwise it will be overwritten PendingIntent dismissActionPI = PendingIntent.getService(context, (int) dismissedTaskId, dismissAction, PendingIntent.FLAG_UPDATE_CURRENT); return new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_nag) .setColor(ContextCompat.getColor(context, R.color.primaryDark)) .setCategory(NotificationCompat.CATEGORY_REMINDER).setPriority(NotificationCompat.PRIORITY_HIGH) .setContentIntent(primaryActionPI).setDeleteIntent(dismissActionPI).setAutoCancel(true) .setWhen(currentTime).setShowWhen(true).setDefaults(NotificationCompat.DEFAULT_ALL); }
From source file:com.example.android.wearable.wear.wearnotifications.handlers.MessagingIntentService.java
private NotificationCompat.Builder recreateBuilderWithMessagingStyle() { // Main steps for building a MESSAGING_STYLE notification (for more detailed comments on // building this notification, check StandaloneMainActivity.java):: // 0. Get your data // 1. Build the MESSAGING_STYLE // 2. Add support for Wear 1.+ // 3. Set up main Intent for notification // 4. Set up RemoteInput (users can input directly from notification) // 5. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData = MockDatabase.getMessagingStyleData(); // 1. Build the Notification.Style (MESSAGING_STYLE) String contentTitle = messagingStyleCommsAppData.getContentTitle(); MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle( messagingStyleCommsAppData.getReplayName()).setConversationTitle(contentTitle); // Adds all Messages for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) { messagingStyle.addMessage(message); }//from www . j a v a2 s. co m // 2. Add support for Wear 1.+. String fullMessageForWearVersion1 = messagingStyleCommsAppData.getFullConversation(); Notification chatHistoryForWearV1 = new NotificationCompat.Builder(getApplicationContext()) .setStyle(new NotificationCompat.BigTextStyle().bigText(fullMessageForWearVersion1)) .setContentTitle(contentTitle).setSmallIcon(R.drawable.ic_launcher) .setContentText(fullMessageForWearVersion1).build(); // Adds page with all text to support Wear 1.+. NotificationCompat.WearableExtender wearableExtenderForWearVersion1 = new NotificationCompat.WearableExtender() .setHintContentIntentLaunchesActivity(true).addPage(chatHistoryForWearV1); // 3. Set up main Intent for notification Intent notifyIntent = new Intent(this, MessagingMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 4. 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(MessagingIntentService.EXTRA_REPLY).setLabel(replyLabel) .build(); Intent replyIntent = new Intent(this, MessagingIntentService.class); replyIntent.setAction(MessagingIntentService.ACTION_REPLY); 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_0 = 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) // Allows system to generate replies by context of conversation .setAllowGeneratedReplies(true) // Add WearableExtender to enable inline actions .extend(inlineActionForWear2_0).build(); // 5. Build and issue the notification NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // Builds and issues notification notificationCompatBuilder.setStyle(messagingStyle).setContentTitle(contentTitle) .setContentText(messagingStyleCommsAppData.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(messagingStyleCommsAppData.getNumberOfNewMessages())) .addAction(replyAction).setCategory(Notification.CATEGORY_MESSAGE) .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PRIVATE) .extend(wearableExtenderForWearVersion1); for (String name : messagingStyleCommsAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } return notificationCompatBuilder; }
From source file:cx.ring.model.Conference.java
public void showCallNotification(Context ctx) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx); notificationManager.cancel(notificationId); if (getParticipants().isEmpty()) return;/*from w w w . j a va 2s . com*/ SipCall call = getParticipants().get(0); CallContact contact = call.getContact(); final Uri call_uri = Uri.withAppendedPath(SipCall.CONTENT_URI, call.getCallId()); PendingIntent goto_intent = PendingIntent.getActivity(ctx, new Random().nextInt(), getViewIntent(ctx), PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder noti = new NotificationCompat.Builder(ctx); if (isOnGoing()) { noti.setContentTitle(ctx.getString(R.string.notif_current_call_title, contact.getDisplayName())) .setContentText(ctx.getText(R.string.notif_current_call)).setContentIntent(goto_intent) .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup), PendingIntent.getService( ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)); } else if (isRinging()) { if (isIncoming()) { noti.setContentTitle(ctx.getString(R.string.notif_incoming_call_title, contact.getDisplayName())) .setPriority(NotificationCompat.PRIORITY_MAX) .setContentText(ctx.getText(R.string.notif_incoming_call)).setContentIntent(goto_intent) .setFullScreenIntent(goto_intent, true) .addAction(R.drawable.ic_action_accept, ctx.getText(R.string.action_call_accept), PendingIntent.getService(ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_ACCEPT) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)) .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_decline), PendingIntent.getService(ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_REFUSE) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)); } else { noti.setContentTitle(ctx.getString(R.string.notif_outgoing_call_title, contact.getDisplayName())) .setContentText(ctx.getText(R.string.notif_outgoing_call)).setContentIntent(goto_intent) .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup), PendingIntent.getService( ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)); } } else { notificationManager.cancel(notificationId); return; } noti.setOngoing(true).setCategory(NotificationCompat.CATEGORY_CALL).setSmallIcon(R.drawable.ic_launcher); if (contact.getPhoto() != null) { Resources res = ctx.getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); noti.setLargeIcon(Bitmap.createScaledBitmap(contact.getPhoto(), width, height, false)); } notificationManager.notify(notificationId, noti.build()); }
From source file:com.hippo.ehviewer.download.DownloadService.java
private void ensureDownloadedBuilder() { if (mDownloadedBuilder != null) { return;/*from w ww. java 2 s. com*/ } Intent clearIntent = new Intent(this, DownloadService.class); clearIntent.setAction(ACTION_CLEAR); PendingIntent piClear = PendingIntent.getService(this, 0, clearIntent, 0); Bundle bundle = new Bundle(); bundle.putString(DownloadsScene.KEY_ACTION, DownloadsScene.ACTION_CLEAR_DOWNLOAD_SERVICE); Intent activityIntent = new Intent(this, MainActivity.class); activityIntent.setAction(StageActivity.ACTION_START_SCENE); activityIntent.putExtra(StageActivity.KEY_SCENE_NAME, DownloadsScene.class.getName()); activityIntent.putExtra(StageActivity.KEY_SCENE_ARGS, bundle); PendingIntent piActivity = PendingIntent.getActivity(DownloadService.this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); mDownloadedBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentTitle(getString(R.string.stat_download_done_title)).setDeleteIntent(piClear) .setOngoing(false).setAutoCancel(true).setContentIntent(piActivity); mDownloadedDelay = new NotificationDelay(this, mNotifyManager, mDownloadedBuilder, ID_DOWNLOADED); }
From source file:com.pluscubed.velociraptor.SettingsActivity.java
@SuppressWarnings("ConstantConditions") @Override/*from w w w. j a v a2 s .c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); ButterKnife.bind(this); setSupportActionBar(toolbar); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { View marshmallowPermissionsCard = findViewById(R.id.card_m_permissions); marshmallowPermissionsCard.setVisibility(View.GONE); } openStreetMapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShareCompat.IntentBuilder.from(SettingsActivity.this).setText("https://www.openstreetmap.org") .setType("text/plain").startChooser(); } }); checkCoverageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mGoogleApiClient = new GoogleApiClient.Builder(SettingsActivity.this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override @SuppressWarnings("MissingPermission") public void onConnected(@Nullable Bundle bundle) { String uriString = "http://product.itoworld.com/map/124"; if (isLocationPermissionGranted()) { Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleApiClient); if (lastLocation != null) { uriString += "?lon=" + lastLocation.getLongitude() + "&lat=" + lastLocation.getLatitude() + "&zoom=12"; } } Intent intent = new Intent(); intent.setData(Uri.parse(uriString)); intent.setAction(Intent.ACTION_VIEW); try { startActivity(intent); } catch (ActivityNotFoundException e) { Snackbar.make(enableFloatingButton, R.string.open_coverage_map_failed, Snackbar.LENGTH_LONG).show(); } mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int i) { } }).addApi(LocationServices.API).build(); mGoogleApiClient.connect(); } }); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); View notifControls = findViewById(R.id.switch_notif_controls); notifControls.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SettingsActivity.this, FloatingService.class); intent.putExtra(FloatingService.EXTRA_NOTIF_START, true); PendingIntent pending = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE, intent, PendingIntent.FLAG_CANCEL_CURRENT); Intent intentClose = new Intent(SettingsActivity.this, FloatingService.class); intentClose.putExtra(FloatingService.EXTRA_NOTIF_CLOSE, true); PendingIntent pendingClose = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE_CLOSE, intentClose, PendingIntent.FLAG_CANCEL_CURRENT); Intent settings = new Intent(SettingsActivity.this, SettingsActivity.class); PendingIntent settingsIntent = PendingIntent.getActivity(SettingsActivity.this, PENDING_SETTINGS, settings, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(SettingsActivity.this) .setSmallIcon(R.drawable.ic_speedometer) .setContentTitle(getString(R.string.controls_notif_title)) .setContentText(getString(R.string.controls_notif_desc)) .addAction(0, getString(R.string.show), pending) .addAction(0, getString(R.string.hide), pendingClose).setDeleteIntent(pendingClose) .setContentIntent(settingsIntent); Notification notification = builder.build(); notificationManager.notify(NOTIFICATION_CONTROLS, notification); } }); Button openAppSelection = (Button) findViewById(R.id.button_app_selection); openAppSelection.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(SettingsActivity.this, AppSelectionActivity.class)); } }); autoDisplaySwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this)); autoDisplaySwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean autoDisplayEnabled = autoDisplaySwitch.isChecked(); PrefUtils.setAutoDisplay(SettingsActivity.this, autoDisplayEnabled); updateAppDetectionEnabled(autoDisplayEnabled); } }); enableServiceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)); } catch (ActivityNotFoundException e) { Snackbar.make(enableServiceButton, R.string.open_settings_failed_accessibility, Snackbar.LENGTH_LONG).show(); } } }); enableFloatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { //Open the current default browswer App Info page openSettings(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, BuildConfig.APPLICATION_ID); } catch (ActivityNotFoundException ignored) { Snackbar.make(enableFloatingButton, R.string.open_settings_failed_overlay, Snackbar.LENGTH_LONG) .show(); } } }); enableLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(SettingsActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } }); ArrayAdapter<String> unitAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text, new String[] { "mph", "km/h" }); unitAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); unitSpinner.setAdapter(unitAdapter); unitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (PrefUtils.getUseMetric(SettingsActivity.this) != (position == 1)) { PrefUtils.setUseMetric(SettingsActivity.this, position == 1); unitSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this, unitSpinner.getSelectedItemPosition() * -48)); updateFloatingServicePrefs(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); unitSpinner.setSelection(PrefUtils.getUseMetric(this) ? 1 : 0); unitSpinner .setDropDownVerticalOffset(Utils.convertDpToPx(this, unitSpinner.getSelectedItemPosition() * -48)); ArrayAdapter<String> styleAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text, new String[] { getString(R.string.united_states), getString(R.string.international) }); styleAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); styleSpinner.setAdapter(styleAdapter); styleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != PrefUtils.getSignStyle(SettingsActivity.this)) { PrefUtils.setSignStyle(SettingsActivity.this, position); styleSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this, styleSpinner.getSelectedItemPosition() * -48)); updateFloatingServicePrefs(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); styleSpinner.setSelection(PrefUtils.getSignStyle(this)); styleSpinner .setDropDownVerticalOffset(Utils.convertDpToPx(this, styleSpinner.getSelectedItemPosition() * -48)); toleranceView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new ToleranceDialogFragment().show(getFragmentManager(), "dialog_tolerance"); } }); showSpeedometerSwitch.setChecked(PrefUtils.getShowSpeedometer(this)); ((View) showSpeedometerSwitch.getParent()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSpeedometerSwitch.setChecked(!showSpeedometerSwitch.isChecked()); PrefUtils.setShowSpeedometer(SettingsActivity.this, showSpeedometerSwitch.isChecked()); updateFloatingServicePrefs(); } }); debuggingSwitch.setChecked(PrefUtils.isDebuggingEnabled(this)); ((View) debuggingSwitch.getParent()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { debuggingSwitch.setChecked(!debuggingSwitch.isChecked()); PrefUtils.setDebugging(SettingsActivity.this, debuggingSwitch.isChecked()); updateFloatingServicePrefs(); } }); beepSwitch.setChecked(PrefUtils.isBeepAlertEnabled(this)); beepSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PrefUtils.setBeepAlertEnabled(SettingsActivity.this, beepSwitch.isChecked()); } }); testBeepButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Utils.playBeep(); } }); androidAutoSwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this)); androidAutoSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = androidAutoSwitch.isChecked(); if (checked) { new MaterialDialog.Builder(SettingsActivity.this) .content(R.string.android_auto_instruction_dialog).positiveText(android.R.string.ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, true); } }).show(); } else { PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, checked); } } }); invalidateStates(); if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this) && !PrefUtils.isFirstRun(this)) { showChangelog(); } billingProcessor = new BillingProcessor(this, getString(R.string.play_license_key), new BillingProcessor.IBillingHandler() { @Override public void onProductPurchased(String productId, TransactionDetails details) { PrefUtils.setSupported(SettingsActivity.this, true); if (Arrays.asList(PURCHASES).contains(productId)) billingProcessor.consumePurchase(productId); } @Override public void onPurchaseHistoryRestored() { } @Override public void onBillingError(int errorCode, Throwable error) { if (errorCode != 110) { Snackbar.make(findViewById(android.R.id.content), "Billing error: code = " + errorCode + ", error: " + (error != null ? error.getMessage() : "?"), Snackbar.LENGTH_LONG).show(); } } @Override public void onBillingInitialized() { billingProcessor.loadOwnedPurchasesFromGoogle(); } }); PrefUtils.setFirstRun(this, false); PrefUtils.setVersionCode(this, BuildConfig.VERSION_CODE); }
From source file:com.devbrackets.android.playlistcore.helper.MediaControlsHelper.java
/** * Creates a PendingIntent for the given action to the specified service * * @param action The action to use//from w ww .jav a2 s.c o m * @param serviceClass The service class to notify of intents * @return The resulting PendingIntent */ @NonNull protected PendingIntent createPendingIntent(@NonNull String action, @NonNull Class<? extends Service> serviceClass) { Intent intent = new Intent(context, serviceClass); intent.setAction(action); return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.granita.tasks.notification.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} for the specified notification action. *///from w w w . j av a2 s. co m public static PendingIntent getNotificationActionPendingIntent(Context context, NotificationAction action) { final Intent intent = new Intent(action.getActionType()); intent.setData(action.getTaskUri()); intent.setPackage(context.getPackageName()); putNotificationActionExtra(intent, action); return PendingIntent.getService(context, action.getNotificationId(), intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:edu.mit.media.funf.configured.ConfiguredPipeline.java
private void cancelAlarm(String action) { Intent i = new Intent(this, getClass()); i.setAction(action);/*from w w w. j a va 2 s . c o m*/ PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pi); } }
From source file:com.android.deskclock.alarms.AlarmNotifications.java
public static void showAlarmNotification(Service service, AlarmInstance instance) { LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId); Resources resources = service.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(service) .setContentTitle(instance.getLabelOrDefault(service)) .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime())) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false) .setDefaults(NotificationCompat.DEFAULT_LIGHTS).setWhen(0) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setLocalOnly(true);// w ww. j a va 2 s . com // Setup Snooze Action Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(service, AlarmStateManager.ALARM_SNOOZE_TAG, instance, AlarmInstance.SNOOZE_STATE); snoozeIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true); PendingIntent snoozePendingIntent = PendingIntent.getService(service, instance.hashCode(), snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.ic_snooze_24dp, resources.getString(R.string.alarm_alert_snooze_text), snoozePendingIntent); // Setup Dismiss Action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(service, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); dismissIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true); PendingIntent dismissPendingIntent = PendingIntent.getService(service, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.ic_alarm_off_24dp, resources.getString(R.string.alarm_alert_dismiss_text), dismissPendingIntent); // Setup Content Action Intent contentIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId); notification.setContentIntent(PendingIntent.getActivity(service, instance.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup fullscreen intent Intent fullScreenIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId); // set action, so we can be different then content pending intent fullScreenIntent.setAction("fullscreen_activity"); fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); notification.setFullScreenIntent(PendingIntent.getActivity(service, instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true); notification.setPriority(NotificationCompat.PRIORITY_MAX); clearNotification(service, instance); service.startForeground(instance.hashCode(), notification.build()); }
From source file:com.orpheusdroid.screenrecorder.RecorderService.java
@TargetApi(24) private void resumeScreenRecording() { mMediaRecorder.resume();/*from w w w .j a v a 2 s . c o m*/ //Reset startTime to current time again startTime = System.currentTimeMillis(); //set Pause action to Notification and update current Notification Intent recordPauseIntent = new Intent(this, RecorderService.class); recordPauseIntent.setAction(Const.SCREEN_RECORDING_PAUSE); PendingIntent precordPauseIntent = PendingIntent.getService(this, 0, recordPauseIntent, 0); NotificationCompat.Action action = new NotificationCompat.Action(android.R.drawable.ic_media_pause, getString(R.string.screen_recording_notification_action_pause), precordPauseIntent); updateNotification( createNotification(action).setUsesChronometer(true) .setWhen((System.currentTimeMillis() - elapsedTime)).build(), Const.SCREEN_RECORDER_NOTIFICATION_ID); Toast.makeText(this, R.string.screen_recording_resumed_toast, Toast.LENGTH_SHORT).show(); }