List of usage examples for android.app PendingIntent FLAG_ONE_SHOT
int FLAG_ONE_SHOT
To view the source code for android.app PendingIntent FLAG_ONE_SHOT.
Click Source Link
From source file:com.sender.team.sender.gcm.MyGcmListenerService.java
private void sendNotification(String message) { Intent intent = new Intent(this, AcceptActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER").setContentTitle("SENDER") .setContentText("? ").setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.intel.RtcPingDownloadTester.java
private void setAlarm(long millis) { Intent intent = new Intent(ACTION_NAME); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Log.v(TAG, "setAlarm millis = " + millis); if (millis == 0) return;//from w w w .j a v a 2 s. co m AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pendingIntent); return; }
From source file:com.lloydtorres.stately.push.TrixHelper.java
/** * Builds and shows a notification for each supported notice type except for issues. * @param c App context// ww w .j a v a 2s . c om * @param account Name/ID of the nation whom the notices belong to. * @param notice The notice to show as a notification. */ public static void processNotice(Context c, String account, Notice notice) { // Check if the user wants to see notifications for this kind of notice if (!SettingsActivity.getIssuesNotificationSetting(c)) { return; } if (Notice.TG.equals(notice.type) && !SettingsActivity.getTelegramsNotificationSetting(c)) { return; } else if (Notice.RMB_MENTION.equals(notice.type) && !SettingsActivity.getRmbMentionNotificationSetting(c)) { return; } else if (Notice.RMB_QUOTE.equals(notice.type) && !SettingsActivity.getRmbQuoteNotificationSetting(c)) { return; } else if (Notice.RMB_LIKE.equals(notice.type) && !SettingsActivity.getRmbLikeNotificationSetting(c)) { return; } else if (Notice.ENDORSE.equals(notice.type) && !SettingsActivity.getEndorsementNotificationSetting(c)) { return; } String title = String.format(Locale.US, c.getString(R.string.time_moments_template), notice.subject, notice.content); // Remove period from end of notification if (title.length() > 1) { title = title.substring(0, title.length() - 1); } String tagSuffix = notice.type; // Handle notification icon and intent int smallIcon = 0; int smallIconCompat = 0; Bundle bundle = new Bundle(); switch (notice.type) { case Notice.TG: smallIcon = R.drawable.ic_menu_telegrams; smallIconCompat = R.drawable.ic_notifs_kitkat_telegram; Matcher matcherTg = NOTIFS_URL_TG.matcher(notice.link); matcherTg.matches(); int telegramId = Integer.valueOf(matcherTg.group(1)); bundle.putInt(LoginActivity.ROUTE_PATH_KEY, LoginActivity.ROUTE_TG); bundle.putInt(TelegramHistoryActivity.ID_DATA, telegramId); break; case Notice.RMB_MENTION: case Notice.RMB_QUOTE: case Notice.RMB_LIKE: smallIcon = R.drawable.ic_region_white; smallIconCompat = R.drawable.ic_notifs_kitkat_region; Matcher rMatcher = NOTIFS_URL_RMB.matcher(notice.link); rMatcher.matches(); String rName = SparkleHelper.getNameFromId(rMatcher.group(1)); int postId = Integer.valueOf(rMatcher.group(2)); bundle.putInt(LoginActivity.ROUTE_PATH_KEY, LoginActivity.ROUTE_RMB); bundle.putString(MessageBoardActivity.BOARD_REGION_NAME, rName); bundle.putInt(MessageBoardActivity.BOARD_TARGET_ID, postId); break; case Notice.ENDORSE: smallIcon = R.drawable.ic_endorse_yes; smallIconCompat = R.drawable.ic_notifs_kitkat_endorse; Matcher matcherEndorse = NOTIFS_URL_ENDORSE.matcher(notice.link); matcherEndorse.matches(); bundle.putInt(LoginActivity.ROUTE_PATH_KEY, LoginActivity.ROUTE_EXPLORE); bundle.putString(ExploreActivity.EXPLORE_ID, matcherEndorse.group(1)); bundle.putInt(ExploreActivity.EXPLORE_MODE, ExploreActivity.EXPLORE_NATION); break; } NotificationCompat.Builder builder = getBaseBuilder(c, account).setContentTitle(title) .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? smallIcon : smallIconCompat) .setContentIntent(PendingIntent.getActivity(c, 0, getLoginActivityIntent(c, account, bundle), PendingIntent.FLAG_ONE_SHOT)); NotificationManager notificationManager = (NotificationManager) c .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(TAG_PREFIX + tagSuffix, (int) notice.timestamp, builder.build()); }
From source file:com.ferdi2005.secondgram.NotificationsController.java
protected void showSingleBackgroundNotification() { notificationsQueue.postRunnable(new Runnable() { @Override//from www. java 2s.co m public void run() { try { if (!ApplicationLoader.mainInterfacePaused) { return; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); boolean notifyDisabled = false; int needVibrate = 0; String choosenSoundPath = null; int ledColor = 0xff0000ff; int priority = 0; int vibrateOverride; if (!preferences.getBoolean("EnableAll", true)) { notifyDisabled = true; } String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); if (!notifyDisabled) { vibrateOverride = 0; choosenSoundPath = null; boolean vibrateOnlyIfSilent = false; if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_messages", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("MessagesLed", 0xff0000ff); if (needVibrate == 4) { vibrateOnlyIfSilent = true; needVibrate = 0; } if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0 && vibrateOverride != 4) { needVibrate = vibrateOverride; } if (vibrateOnlyIfSilent && needVibrate != 2) { try { int mode = audioManager.getRingerMode(); if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) { needVibrate = 2; } } catch (Exception e) { FileLog.e(e); } } } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); String name = LocaleController.getString("AppName", R.string.AppName); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setAutoCancel(true) .setNumber(total_unread_count).setContentIntent(contentIntent) .setGroup("messages").setGroupSummary(true).setColor(0xff2ca5e0); mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE); String lastMessage = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage); mBuilder.setContentText(lastMessage); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(lastMessage)); if (priority == 0) { mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); } else if (priority == 1) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } else if (priority == 2) { mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); } if (!notifyDisabled) { if (lastMessage.length() > 100) { lastMessage = lastMessage.substring(0, 100).replace('\n', ' ').trim() + "..."; } mBuilder.setTicker(lastMessage); if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) { if (choosenSoundPath.equals(defaultPath)) { mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); } else { mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION); } } if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } if (needVibrate == 2 || MediaController.getInstance().isRecordingAudio()) { mBuilder.setVibrate(new long[] { 0, 0 }); } else if (needVibrate == 1) { mBuilder.setVibrate(new long[] { 0, 100, 0, 100 }); } else if (needVibrate == 0 || needVibrate == 4) { mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); } else if (needVibrate == 3) { mBuilder.setVibrate(new long[] { 0, 1000 }); } } else { mBuilder.setVibrate(new long[] { 0, 0 }); } notificationManager.notify(1, mBuilder.build()); } catch (Exception e) { FileLog.e(e); } } }); }
From source file:com.snda.mymarket.providers.downloads.DownloadService.java
/** * Update {@link #mDownloads} to match {@link DownloadProvider} state. * Depending on current download state it may enqueue {@link DownloadThread} * instances, request {@link DownloadScanner} scans, update user-visible * notifications, and/or schedule future actions with {@link AlarmManager}. * <p>/* w w w.j a v a2 s . c o m*/ * Should only be called from {@link #mUpdateThread} as after being * requested through {@link #enqueueUpdate()}. * * @return If there are active tasks being processed, as of the database * snapshot taken in this update. */ private boolean updateLocked() { final long now = mSystemFacade.currentTimeMillis(); boolean isActive = false; long nextActionMillis = Long.MAX_VALUE; final Set<Long> staleIds = new HashSet<Long>(mDownloads.size()); final ContentResolver resolver = getContentResolver(); final Cursor cursor = resolver.query(Downloads.ALL_DOWNLOADS_CONTENT_URI, null, null, null, null); try { final DownloadInfo.Reader reader = new DownloadInfo.Reader(resolver, cursor); final int idColumn = cursor.getColumnIndexOrThrow(Downloads._ID); while (cursor.moveToNext()) { final long id = cursor.getLong(idColumn); staleIds.remove(id); DownloadInfo info = mDownloads.get(id); if (info != null) { updateDownload(reader, info, now); } else { info = insertDownloadLocked(reader, now); } if (info.mDeleted) { // Delete download if requested, but only after cleaning up if (!TextUtils.isEmpty(info.mMediaProviderUri)) { resolver.delete(Uri.parse(info.mMediaProviderUri), null, null); } Helpers.deleteFile(getContentResolver(), info.mId, info.mFileName, info.mMimeType); } else { // Kick off download task if ready final boolean activeDownload = info.startIfReady(this.mNotifier); final boolean activeScan = info.startScanIfReady(mScanner); if (DEBUG_LIFECYCLE && (activeDownload || activeScan)) { Log.v(Constants.TAG, "Download " + info.mId + ": activeDownload=" + activeDownload + ", activeScan=" + activeScan); } isActive |= activeDownload; isActive |= activeScan; } // Keep track of nearest next action nextActionMillis = Math.min(info.nextActionMillis(now), nextActionMillis); } } finally { cursor.close(); } // Clean up stale downloads that disappeared for (Long id : staleIds) { deleteDownloadLocked(id); } // Update notifications visible to user mNotifier.updateWith(mDownloads); // Set alarm when next action is in future. It's okay if the service // continues to run in meantime, since it will kick off an update pass. if (nextActionMillis > 0 && nextActionMillis < Long.MAX_VALUE) { if (Constants.LOGV) { Log.v(Constants.TAG, "scheduling start in " + nextActionMillis + "ms"); } final Intent intent = new Intent(Constants.ACTION_RETRY); intent.setClass(this, DownloadReceiver.class); mAlarmManager.set(AlarmManager.RTC_WAKEUP, now + nextActionMillis, PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)); } return isActive; }
From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java
public void notifyUndefined(String title, String text) { Intent contentIntent = new Intent(this, MainActivity.class); //contentIntent.putExtra("navigation_page", MainActivity.PAGE_ANNOUNCEMENTS); contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent, PendingIntent.FLAG_ONE_SHOT); Intent settingsIntent = new Intent(this, MainActivity.class); settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle(); notifStyle.bigText(text);/* w w w .j a v a 2s. c om*/ notifStyle.setBigContentTitle(title); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon_nodpi).setContentTitle(title).setContentText(text) .setAutoCancel(true).setSound(defaultSoundUri) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent) .setStyle(notifStyle); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(NOTIFICATION_ID_UNDEFINED, notificationBuilder.build()); }
From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java
public void setupAlarm(int hourOfDay) { //Alarm has been called ALARM_NOT_CALLED = false;/*from w ww. ja va 2 s . com*/ //Setup what the alarm has to do when it goes off. Intent alarmIntent = new Intent(SmogMapActivity.this, AirAzureDownloadService.AlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(SmogMapActivity.this, 0, alarmIntent, PendingIntent.FLAG_ONE_SHOT);//getBroadcast(context, 0, i, 0); Log.v("OnCreate", "Alarm Intent Created"); //Set the AlarmManager to wake up the system every day at 6 a.m. AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); long timeEveryDay = calendar.getTimeInMillis(); long currentTime = System.currentTimeMillis(); long oneMin = 60 * 1000; am.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeEveryDay, AlarmManager.INTERVAL_DAY, pi); if ((currentTime + oneMin) < timeEveryDay) { Log.v(LOG_TAG, "First time download and time is before 6 a.m."); Intent firstTimeDownloadIntent = new Intent(getApplicationContext(), AirAzureDownloadService.class); startService(firstTimeDownloadIntent); } }
From source file:com.sender.team.sender.gcm.MyGcmListenerService.java
private void sendRejectNotification() { Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(ACTION_REJECT, "reject"); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER").setContentTitle("SENDER") .setContentText("? ?").setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void showCollapsedNotificationWithNext(final Context context, String title, String text, Long nextBroadcastTime) { LogUtils.d(TAG, "showCollapsedNotificationWithNext nextBroadcastTime: %d", nextBroadcastTime); Intent activityIntent = new Intent(context, DeskClock.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX); PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); showCollapsedNotification(context, title, text, NotificationCompat.PRIORITY_HIGH, pendingActivityIntent, IN_USE_NOTIFICATION_ID, false); if (nextBroadcastTime == null) { return;/*from w w w .j av a 2 s .c o m*/ } Intent nextBroadcast = new Intent(); nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW); PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } else { alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } }
From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java
public void notifyUndefined(String title, String text, String URL) { Uri webpage = Uri.parse(URL); Intent contentIntent = new Intent(Intent.ACTION_VIEW, webpage); PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent, PendingIntent.FLAG_ONE_SHOT); Intent settingsIntent = new Intent(this, MainActivity.class); settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle(); notifStyle.bigText(text);//from w w w . j ava 2s . co m notifStyle.setBigContentTitle(title); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon_nodpi).setContentTitle(title).setContentText(text) .setAutoCancel(true).setSound(defaultSoundUri) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent) .setStyle(notifStyle); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(NOTIFICATION_ID_UNDEFINED, notificationBuilder.build()); }