List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java
/** * Schedule new notification/*w w w. j a va2s. c o m*/ */ public void schedule(Options options) { long triggerTime = options.getDate(); persist(options.getId(), options.getJSONObject()); //Intent is called when the Notification gets fired Intent intent = new Intent(context, receiver).setAction("" + options.getId()).putExtra(OPTIONS, options.getJSONObject().toString()); AlarmManager am = getAlarmManager(); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi); }
From source file:com.morlunk.mumbleclient.service.PlumbleMessageNotification.java
/** * Shows the notification with the provided message. * If the notification is already shown, append the message to the existing notification. * @param message The message to notify the user about. *//* w w w.ja v a2s .co m*/ public void show(IMessage message) { mUnreadMessages.add(message); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); style.setBigContentTitle(mContext.getString(R.string.notification_unread_many, mUnreadMessages.size())); for (IMessage m : mUnreadMessages) { String line = mContext.getString(R.string.notification_message, m.getActorName(), m.getMessage()); style.addLine(line); } Intent channelListIntent = new Intent(mContext, PlumbleActivity.class); channelListIntent.putExtra(PlumbleActivity.EXTRA_DRAWER_FRAGMENT, DrawerAdapter.ITEM_SERVER); // FLAG_CANCEL_CURRENT ensures that the extra always gets sent. PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, channelListIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) .setPriority(NotificationCompat.PRIORITY_HIGH).setSmallIcon(R.drawable.ic_stat_notify) .setContentIntent(pendingIntent).setAutoCancel(true).setTicker(message.getActorName()) .setContentTitle(message.getActorName()).setContentText(message.getMessage()) .setVibrate(VIBRATION_PATTERN).setStyle(style); if (mUnreadMessages.size() > 0) builder.setNumber(mUnreadMessages.size()); final NotificationManagerCompat manager = NotificationManagerCompat.from(mContext); Notification notification = builder.build(); manager.notify(NOTIFICATION_ID, notification); }
From source file:com.phonemetra.account.util.AccountUtils.java
public static void scheduleRetry(Context context, SharedPreferences prefs, Intent intent) { int backoffTimeMs = getBackoff(prefs); int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs); if (Account.DEBUG) Log.d(TAG, "Scheduling retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ") for " + intent.getAction());//from w w w .j av a 2 s . c o m PendingIntent retryPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent); if (backoffTimeMs < Account.MAX_BACKOFF_MS) { setBackoff(prefs, backoffTimeMs * 2); } }
From source file:com.afrozaar.jazzfestreporting.ResumableUpload.java
/** * Uploads user selected video in the project folder to the user's YouTube account using OAuth2 * for authentication.// w w w .j a va 2s. com */ public static String upload(YouTube youtube, final InputStream fileInputStream, final long fileSize, final Uri mFileUri, final String path, final Context context) { final NotificationManager notifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Intent notificationIntent = new Intent(context, ReviewActivity.class); notificationIntent.setData(mFileUri); notificationIntent.setAction(Intent.ACTION_VIEW); Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MICRO_KIND); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentTitle(context.getString(R.string.youtube_upload)) .setContentText(context.getString(R.string.youtube_upload_started)) .setSmallIcon(R.drawable.ic_stat_device_access_video).setContentIntent(contentIntent) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(thumbnail)); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); String videoId = null; try { // Add extra information to the video before uploading. Video videoObjectDefiningMetadata = new Video(); /* * Set the video to public, so it is available to everyone (what most people want). This is * actually the default, but I wanted you to see what it looked like in case you need to set * it to "unlisted" or "private" via API. */ VideoStatus status = new VideoStatus(); status.setPrivacyStatus("public"); videoObjectDefiningMetadata.setStatus(status); // We set a majority of the metadata with the VideoSnippet object. VideoSnippet snippet = new VideoSnippet(); /* * The Calendar instance is used to create a unique name and description for test purposes, so * you can see multiple files being uploaded. You will want to remove this from your project * and use your own standard names. */ Calendar cal = Calendar.getInstance(); snippet.setTitle("Test Upload via Java on " + cal.getTime()); snippet.setDescription( "Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime()); // Set your keywords. snippet.setTags(Arrays.asList(Constants.DEFAULT_KEYWORD, Upload.generateKeywordFromPlaylistId(Constants.UPLOAD_PLAYLIST))); // Set completed snippet to the video object. videoObjectDefiningMetadata.setSnippet(snippet); InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT, new BufferedInputStream(fileInputStream)); mediaContent.setLength(fileSize); /* * The upload command includes: 1. Information we want returned after file is successfully * uploaded. 2. Metadata we want associated with the uploaded video. 3. Video file itself. */ YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent); // Set the upload type and add event listener. MediaHttpUploader uploader = videoInsert.getMediaHttpUploader(); /* * Sets whether direct media upload is enabled or disabled. True = whole media content is * uploaded in a single request. False (default) = resumable media upload protocol to upload * in data chunks. */ uploader.setDirectUploadEnabled(false); MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() { public void progressChanged(MediaHttpUploader uploader) throws IOException { switch (uploader.getUploadState()) { case INITIATION_STARTED: builder.setContentText(context.getString(R.string.initiation_started)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case INITIATION_COMPLETE: builder.setContentText(context.getString(R.string.initiation_completed)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case MEDIA_IN_PROGRESS: builder.setContentTitle(context.getString(R.string.youtube_upload) + (int) (uploader.getProgress() * 100) + "%") .setContentText(context.getString(R.string.upload_in_progress)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case MEDIA_COMPLETE: builder.setContentTitle(context.getString(R.string.yt_upload_completed)) .setContentText(context.getString(R.string.upload_completed)) // Removes the progress bar .setProgress(0, 0, false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); case NOT_STARTED: Log.d(this.getClass().getSimpleName(), context.getString(R.string.upload_not_started)); break; } } }; uploader.setProgressListener(progressListener); // Execute upload. Video returnedVideo = videoInsert.execute(); Log.d(TAG, "Video upload completed"); videoId = returnedVideo.getId(); Log.d(TAG, String.format("videoId = [%s]", videoId)); } catch (final GooglePlayServicesAvailabilityIOException availabilityException) { Log.e(TAG, "GooglePlayServicesAvailabilityIOException", availabilityException); notifyFailedUpload(context, context.getString(R.string.cant_access_play), notifyManager, builder); } catch (UserRecoverableAuthIOException userRecoverableException) { Log.i(TAG, String.format("UserRecoverableAuthIOException: %s", userRecoverableException.getMessage())); requestAuth(context, userRecoverableException); } catch (IOException e) { Log.e(TAG, "IOException", e); notifyFailedUpload(context, context.getString(R.string.please_try_again), notifyManager, builder); } return videoId; }
From source file:org.youtube.Youtube_ResumableUpload.java
/** * Uploads user selected video in the project folder to the user's YouTube account using OAuth2 * for authentication./*from www . j ava2 s . com*/ */ public static String upload(YouTube youtube, final InputStream fileInputStream, final long fileSize, final Uri mFileUri, final String path, final Context context) { final NotificationManager notifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Intent notificationIntent = new Intent(context, Youtube_ReviewActivity.class); notificationIntent.setData(mFileUri); notificationIntent.setAction(Intent.ACTION_VIEW); Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MICRO_KIND); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentTitle(context.getString(R.string.youtube_upload)) .setContentText(context.getString(R.string.youtube_upload_started)) .setSmallIcon(R.drawable.ic_stat_device_access_video).setContentIntent(contentIntent) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(thumbnail)); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); String videoId = null; try { // Add extra information to the video before uploading. Video videoObjectDefiningMetadata = new Video(); /* * Set the video to public, so it is available to everyone (what most people want). This is * actually the default, but I wanted you to see what it looked like in case you need to set * it to "unlisted" or "private" via API. */ VideoStatus status = new VideoStatus(); status.setPrivacyStatus("public"); videoObjectDefiningMetadata.setStatus(status); // We set a majority of the metadata with the VideoSnippet object. VideoSnippet snippet = new VideoSnippet(); /* * The Calendar instance is used to create a unique name and description for test purposes, so * you can see multiple files being uploaded. You will want to remove this from your project * and use your own standard names. */ Calendar cal = Calendar.getInstance(); snippet.setTitle("Test Upload via Java on " + cal.getTime()); snippet.setDescription( "Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime()); // Set your keywords. snippet.setTags(Arrays.asList(Youtube_Constants.DEFAULT_KEYWORD, Upload.generateKeywordFromPlaylistId(Youtube_Constants.UPLOAD_PLAYLIST))); // Set completed snippet to the video object. videoObjectDefiningMetadata.setSnippet(snippet); InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT, new BufferedInputStream(fileInputStream)); mediaContent.setLength(fileSize); /* * The upload command includes: 1. Information we want returned after file is successfully * uploaded. 2. Metadata we want associated with the uploaded video. 3. Video file itself. */ YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent); // Set the upload type and add event listener. MediaHttpUploader uploader = videoInsert.getMediaHttpUploader(); /* * Sets whether direct media upload is enabled or disabled. True = whole media content is * uploaded in a single request. False (default) = resumable media upload protocol to upload * in data chunks. */ uploader.setDirectUploadEnabled(false); MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() { public void progressChanged(MediaHttpUploader uploader) throws IOException { switch (uploader.getUploadState()) { case INITIATION_STARTED: builder.setContentText(context.getString(R.string.initiation_started)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case INITIATION_COMPLETE: builder.setContentText(context.getString(R.string.initiation_completed)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case MEDIA_IN_PROGRESS: builder.setContentTitle(context.getString(R.string.youtube_upload) + (int) (uploader.getProgress() * 100) + "%") .setContentText(context.getString(R.string.upload_in_progress)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case MEDIA_COMPLETE: builder.setContentTitle(context.getString(R.string.yt_upload_completed)) .setContentText(context.getString(R.string.upload_completed)) // Removes the progress bar .setProgress(0, 0, false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); case NOT_STARTED: Log.d(this.getClass().getSimpleName(), context.getString(R.string.upload_not_started)); break; } } }; uploader.setProgressListener(progressListener); // Execute upload. Video returnedVideo = videoInsert.execute(); Log.d(TAG, "Video upload completed"); videoId = returnedVideo.getId(); Log.d(TAG, String.format("videoId = [%s]", videoId)); } catch (final GooglePlayServicesAvailabilityIOException availabilityException) { Log.e(TAG, "GooglePlayServicesAvailabilityIOException", availabilityException); notifyFailedUpload(context, context.getString(R.string.cant_access_play), notifyManager, builder); } catch (UserRecoverableAuthIOException userRecoverableException) { Log.i(TAG, String.format("UserRecoverableAuthIOException: %s", userRecoverableException.getMessage())); requestAuth(context, userRecoverableException); } catch (IOException e) { Log.e(TAG, "IOException", e); notifyFailedUpload(context, context.getString(R.string.please_try_again), notifyManager, builder); } return videoId; }
From source file:com.cryart.sabbathschool.misc.SSReminderService.java
@Override public boolean onStartJob(JobParameters job) { Context context = getBaseContext(); SSReminder.scheduleAlarms(context);//from ww w . jav a2 s . com try { String channelId = "ss_notification_channel"; String channelName = getString(R.string.app_name); NotificationManager _SSNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(channelId, channelName, importance); _SSNotificationManager.createNotificationChannel(mChannel); } Intent _SSContentIntent = new Intent(context, SSSplashActivity.class); Intent _SSShareIntent = new Intent(); _SSContentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _SSShareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _SSShareIntent.setAction(Intent.ACTION_SEND); _SSShareIntent.putExtra(Intent.EXTRA_TEXT, ""); _SSShareIntent.setType("*/*"); PendingIntent _SSPendingContentIntent = PendingIntent.getActivity(context, 0, _SSContentIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent _SSPendingShareIntent = PendingIntent.getActivity(context, 0, Intent.createChooser(_SSShareIntent, context.getString(R.string.ss_share)), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder _SSNotificationBuilder = new NotificationCompat.Builder(context, "ss_notification_channel").setSmallIcon(R.mipmap.ic_stat_notification) .setContentTitle(context.getString(R.string.ss_app_name)) .setColor(Color.parseColor(SSColorTheme.getInstance().getColorPrimary())) .addAction(0, context.getString(R.string.ss_menu_read_now), _SSPendingContentIntent) .addAction(0, context.getString(R.string.ss_share), _SSPendingShareIntent) .setAutoCancel(true).setVibrate(new long[] { 1000, 1000 }) .setContentIntent(_SSPendingContentIntent) .setContentText(context.getString(R.string.ss_settings_reminder_text)); _SSNotificationManager.notify(1, _SSNotificationBuilder.build()); } catch (Exception e) { Crashlytics.log(e.getMessage()); } return false; // Answers the question: "Is there still work going on?" }
From source file:com.nextgis.mobile.datasource.SyncAdapter.java
public void sendNotification(Context context, String notificationType, String message) { if (!PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SettingsConstants.KEY_PREF_SHOW_SYNC, false))//w w w .ja va 2 s.c o m return; Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_action_sync).setWhen(System.currentTimeMillis()) .setContentIntent(contentIntent).setAutoCancel(true).setOngoing(false); Bitmap largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_sync, context.getResources()); switch (notificationType) { case SYNC_START: largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_next_dark, context.getResources()); builder.setProgress(0, 0, true).setTicker(context.getString(com.nextgis.maplib.R.string.sync_started)) .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization)) .setContentText(context.getString(com.nextgis.maplib.R.string.sync_progress)); break; case SYNC_FINISH: largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_apply_dark, context.getResources()); builder.setProgress(0, 0, false).setTicker(context.getString(com.nextgis.maplib.R.string.sync_finished)) .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization)) .setContentText(context.getString(com.nextgis.maplib.R.string.sync_finished)); break; case SYNC_CANCELED: largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_cancel_dark, context.getResources()); builder.setProgress(0, 0, false).setTicker(context.getString(com.nextgis.maplib.R.string.sync_canceled)) .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization)) .setContentText(context.getString(com.nextgis.maplib.R.string.sync_canceled)); break; case SYNC_CHANGES: largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_warning_dark, context.getResources()); builder.setProgress(0, 0, false).setTicker(context.getString(com.nextgis.maplib.R.string.sync_error)) .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization)) .setContentText(message); break; } builder.setLargeIcon(largeIcon); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, builder.build()); }
From source file:de.dreier.mytargets.WearableListener.java
private void showNotification(NotificationInfo info) { // Build the intent to display our custom notification Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.putExtra(MainActivity.EXTRA_ROUND, Parcels.wrap(info.round)); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); // Build activity page Notification page = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .extend(new Notification.WearableExtender() .setCustomSizePreset(Notification.WearableExtender.SIZE_FULL_SCREEN) .setDisplayIntent(pendingIntent)) .build();// w w w. j av a 2 s . co m // Create the ongoing notification Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.wear_bg); Notification.Builder notificationBuilder = new Notification.Builder(this).setContentTitle(info.title) .setContentText(info.text).setSmallIcon(R.mipmap.ic_launcher).setOngoing(true) .extend(new Notification.WearableExtender().addPage(page).setBackground(image)); // Build the notification and show it NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); }
From source file:edu.mit.media.realityanalysis.fieldtest.MainPipeline.java
@Override public void onCreate() { super.onCreate(); String password = getDataPassword(this); // If the user hasn't logged in yet, we need to stop the service // NOTE: this currently doesn't work properly because we're just using the default password (changeme) if (password == null || password == "") { Intent loginIntent = new Intent(this, LoginActivity.class); startActivity(loginIntent);// w w w .jav a 2 s .co m this.stopSelf(); } else { setEncryptionPassword(getDataPassword(this).toCharArray()); } //Setup the notification service to run periodically Intent notificationIntent = new Intent(this, NotificationService.class); PendingIntent notificationPendingIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_HALF_HOUR, notificationPendingIntent); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToGroupObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { try {/*w w w. j a va 2 s. com*/ String groupName = obj.getString(GROUP_NAME); Uri dynUpdateUri = Uri.parse(obj.getString(DYN_UPDATE_URI)); Intent launch = new Intent(Intent.ACTION_VIEW); launch.setData(dynUpdateUri); launch.putExtra("type", TYPE); launch.putExtra("creator", false); launch.putExtra(SENDER, from.id); launch.putExtra(GROUP_NAME, groupName); launch.putExtra(DYN_UPDATE_URI, dynUpdateUri); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("Invitation from " + from.name, "Invitation from " + from.name, "Join the group '" + groupName + "'.", contentIntent); } catch (JSONException e) { Log.e(TAG, "Error handling message: ", e); } }