List of usage examples for android.app Notification FLAG_ONGOING_EVENT
int FLAG_ONGOING_EVENT
To view the source code for android.app Notification FLAG_ONGOING_EVENT.
Click Source Link
From source file:org.opensilk.music.playback.NotificationHelper.java
private void buildNotificationInternal() { if (mCurrentInfo.hasAnyNull() || mService == null) { return;//from w w w.ja va 2s. co m } // Default notfication layout mNotificationTemplate = new RemoteViews(mContext.getPackageName(), R.layout.notification_template_base); // Set up the content view initCollapsedLayout(mCurrentInfo.track.name, mCurrentInfo.track.artistName, mCurrentInfo.bitmap); // Notification Builder mNotification = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.stat_notify_music) .setContentIntent(getPendingIntent()).setPriority(NotificationCompat.PRIORITY_DEFAULT) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_TRANSPORT).setContent(mNotificationTemplate).build(); // Control playback from the notification initPlaybackActions(mCurrentInfo.isPlaying); if (VersionUtils.hasJellyBean()) { // Expanded notifiction style mExpandedView = new RemoteViews(mContext.getPackageName(), R.layout.notification_template_expanded_base); mNotification.bigContentView = mExpandedView; // Control playback from the notification initExpandedPlaybackActions(mCurrentInfo.isPlaying); // Set up the expanded content view initExpandedLayout(mCurrentInfo.track.name, mCurrentInfo.track.albumName, mCurrentInfo.track.artistName, mCurrentInfo.bitmap); } mNotification.flags |= Notification.FLAG_ONGOING_EVENT; mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification); }
From source file:io.github.carlorodriguez.alarmon.AlarmClockService.java
private void refreshNotification() { String resolvedString = getString(R.string.no_pending_alarms); AlarmTime nextTime = pendingAlarms.nextAlarmTime(); if (nextTime != null) { Map<String, String> values = new HashMap<>(); values.put("t", nextTime.localizedString(getApplicationContext())); values.put("c", nextTime.timeUntilString(getApplicationContext())); String templateString = AppSettings.getNotificationTemplate(getApplicationContext()); StrSubstitutor sub = new StrSubstitutor(values); resolvedString = sub.replace(templateString); }/* w w w . j a va 2 s. c o m*/ // Make the notification launch the UI Activity when clicked. final Intent notificationIntent = new Intent(this, ActivityAlarmClock.class); final PendingIntent launch = PendingIntent.getActivity(this, 0, notificationIntent, 0); Context c = getApplicationContext(); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); String notificationTitle = getString(R.string.app_name); if (pendingAlarms.nextAlarmId() != AlarmClockServiceBinder.NO_ALARM_ID) { DbAccessor db = new DbAccessor(getApplicationContext()); AlarmInfo alarmInfo = db.readAlarmInfo(pendingAlarms.nextAlarmId()); if (alarmInfo != null) { notificationTitle = alarmInfo.getName() != null && !alarmInfo.getName().isEmpty() ? alarmInfo.getName() : getString(R.string.app_name); } db.closeConnections(); } Notification notification = builder.setContentIntent(launch).setSmallIcon(R.drawable.ic_stat_notify_alarm) .setContentTitle(notificationTitle).setContentText(resolvedString) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.notification_color)).build(); notification.flags |= Notification.FLAG_ONGOING_EVENT; final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (pendingAlarms.size() > 0 && AppSettings.displayNotificationIcon(c)) { manager.notify(NOTIFICATION_BAR_ID, notification); } else { manager.cancel(NOTIFICATION_BAR_ID); } setSystemAlarmStringOnLockScreen(getApplicationContext(), nextTime); }
From source file:de.hackerspacebremen.push.PushIntentService.java
public void displayNotification(final Context context, final SpaceData data, final boolean vibrationEnabled, final boolean permanentNotification) throws JSONException { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); final boolean permanent = permanentNotification && data.isSpaceOpen(); String timeString = context.getString(R.string.unknown); Date time = data.getTime();/*from www .j a va2 s . c o m*/ if (time != null) { timeString = SpeakingDateFormat.format(time); } int icon; CharSequence notificationText; final CharSequence contentTitle; if (data.isSpaceOpen()) { icon = R.drawable.notification_open; notificationText = context.getString(R.string.space_open, timeString); contentTitle = context.getString(R.string.space_open_simple); } else { icon = R.drawable.notification_closed; notificationText = context.getString(R.string.space_closed, timeString); contentTitle = context.getString(R.string.space_closed_simple); } long when = System.currentTimeMillis(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon); builder.setTicker(notificationText); builder.setWhen(when); if (data.getMessage() != null && data.getMessage().length() > 0) { builder.setStyle(new NotificationCompat.BigTextStyle().setSummaryText(notificationText) .bigText("Nachricht: \n" + data.getMessage())); } if (!permanent) { builder.setAutoCancel(true); } builder.setContentTitle(contentTitle); builder.setContentText(notificationText); Intent notificationIntent = new Intent(context, StartActivity.class); notificationIntent.putExtra("status_json", SpaceDataJsonParser.parse(data).toString()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); builder.setContentIntent(contentIntent); final Notification notification = builder.build(); if (vibrationEnabled) { notification.defaults |= Notification.DEFAULT_VIBRATE; } if (permanent) { notification.flags |= Notification.FLAG_ONGOING_EVENT; } mNotificationManager.notify(Constants.NOTIFICATION_ID, notification); }
From source file:edu.stanford.junction.sample.partyware.ImgurUploadService.java
/** * This method uploads an image from the given uri. It does the uploading in * small chunks to make sure it doesn't over run the memory. * //from w w w .j a v a 2s . co m * @param uri * image location * @return map containing data from interaction */ private String readPictureDataAndUpload(final Uri uri) { Log.i(this.getClass().getName(), "in readPictureDataAndUpload(Uri)"); try { final AssetFileDescriptor assetFileDescriptor = getContentResolver().openAssetFileDescriptor(uri, "r"); final int totalFileLength = (int) assetFileDescriptor.getLength(); assetFileDescriptor.close(); // Create custom progress notification mProgressNotification = new Notification(R.drawable.icon, getString(R.string.imgur_upload_in_progress), System.currentTimeMillis()); // set as ongoing mProgressNotification.flags |= Notification.FLAG_ONGOING_EVENT; // set custom view to notification mProgressNotification.contentView = generateProgressNotificationView(0, totalFileLength); //empty intent for the notification final Intent progressIntent = new Intent(); final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, progressIntent, 0); mProgressNotification.contentIntent = contentIntent; // add notification to manager mNotificationManager.notify(NOTIFICATION_ID, mProgressNotification); final InputStream inputStream = getContentResolver().openInputStream(uri); final String boundaryString = "Z." + Long.toHexString(System.currentTimeMillis()) + Long.toHexString((new Random()).nextLong()); final String boundary = "--" + boundaryString; final HttpURLConnection conn = (HttpURLConnection) (new URL("http://imgur.com/api/upload.json")) .openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-type", "multipart/form-data; boundary=\"" + boundaryString + "\""); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.setChunkedStreamingMode(CHUNK_SIZE); final OutputStream hrout = conn.getOutputStream(); final PrintStream hout = new PrintStream(hrout); hout.println(boundary); hout.println("Content-Disposition: form-data; name=\"key\""); hout.println("Content-Type: text/plain"); hout.println(); Random rng = new Random(); String key = API_KEYS[rng.nextInt(API_KEYS.length)]; hout.println(key); hout.println(boundary); hout.println("Content-Disposition: form-data; name=\"image\""); hout.println("Content-Transfer-Encoding: base64"); hout.println(); hout.flush(); { final Base64OutputStream bhout = new Base64OutputStream(hrout); final byte[] pictureData = new byte[READ_BUFFER_SIZE_BYTES]; int read = 0; int totalRead = 0; long lastLogTime = 0; while (read >= 0) { read = inputStream.read(pictureData); if (read > 0) { bhout.write(pictureData, 0, read); totalRead += read; if (lastLogTime < (System.currentTimeMillis() - PROGRESS_UPDATE_INTERVAL_MS)) { lastLogTime = System.currentTimeMillis(); Log.d(this.getClass().getName(), "Uploaded " + totalRead + " of " + totalFileLength + " bytes (" + (100 * totalRead) / totalFileLength + "%)"); //make a final version of the total read to make the handler happy final int totalReadFinal = totalRead; mHandler.post(new Runnable() { public void run() { mProgressNotification.contentView = generateProgressNotificationView( totalReadFinal, totalFileLength); mNotificationManager.notify(NOTIFICATION_ID, mProgressNotification); } }); } bhout.flush(); hrout.flush(); } } Log.d(this.getClass().getName(), "Finishing upload..."); // This close is absolutely necessary, this tells the // Base64OutputStream to finish writing the last of the data // (and including the padding). Without this line, it will miss // the last 4 chars in the output, missing up to 3 bytes in the // final output. bhout.close(); Log.d(this.getClass().getName(), "Upload complete..."); mProgressNotification.contentView.setProgressBar(R.id.UploadProgress, totalFileLength, totalRead, false); mNotificationManager.cancelAll(); } hout.println(boundary); hout.flush(); hrout.close(); inputStream.close(); Log.d(this.getClass().getName(), "streams closed, " + "now waiting for response from server"); final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); final StringBuilder rData = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { rData.append(line).append('\n'); } return rData.toString(); } catch (final IOException e) { Log.e(this.getClass().getName(), "Upload failed", e); } return null; }
From source file:com.b44t.messenger.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(MessageObject messageObject) { AudioInfo audioInfo = MediaController.getInstance().getAudioInfo(); MrPoortext pt = MrMailbox.getMsg(messageObject.getId()).getMediainfo(); String authorName = pt.getText1(); String songName = pt.getText2(); if (songName == null || songName.length() == 0) { TLRPC.Document document = messageObject.messageOwner.media.document; for (int i = 0; i < document.attributes.size(); i++) { TLRPC.DocumentAttribute attr = document.attributes.get(i); if (attr instanceof TLRPC.TL_documentAttributeAudio) { authorName = attr.performer; songName = attr.title;// www. ja v a 2s . c o m break; } } } if (songName == null || songName.length() == 0) { // preview of just recorded and not send voice messages authorName = ApplicationLoader.applicationContext.getString(R.string.FromSelf); songName = ApplicationLoader.applicationContext.getString(R.string.AttachVoiceMessage); } RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); //Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); //intent.setAction("com.b44t.messenger.openchat"+messageObject.getDialogId()); //intent.setFlags(32768); //PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification_player) //.setContentIntent(contentIntent) .setContentTitle(songName).build(); notification.contentView = simpleContentView; setListeners(simpleContentView); Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); notification.contentView.setViewVisibility(R.id.player_album_art, View.VISIBLE); } else { notification.contentView.setViewVisibility(R.id.player_album_art, View.GONE); } { notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover() != null) { try { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); } catch (Throwable e) { FileLog.e("messenger", e); } } metadataEditor.apply(); } }
From source file:com.evandroid.musica.broadcastReceiver.MusicBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { /** Google Play Music //bool streaming long position //long albumId String album //bool currentSongLoaded String track //long ListPosition long ListSize //long id bool playing //long duration int previewPlayType //bool supportsRating int domain //bool albumArtFromService String artist //int rating bool local //bool preparing bool inErrorState */// ww w .j av a2 s . com Bundle extras = intent.getExtras(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); boolean lengthFilter = sharedPref.getBoolean("pref_filter_20min", true); if (extras != null) try { extras.getInt("state"); } catch (BadParcelableException e) { return; } if (extras == null || extras.getInt("state") > 1 //Tracks longer than 20min are presumably not songs || (lengthFilter && (extras.get("duration") instanceof Long && extras.getLong("duration") > 1200000) || (extras.get("duration") instanceof Double && extras.getDouble("duration") > 1200000) || (extras.get("duration") instanceof Integer && extras.getInt("duration") > 1200)) || (lengthFilter && (extras.get("secs") instanceof Long && extras.getLong("secs") > 1200000) || (extras.get("secs") instanceof Double && extras.getDouble("secs") > 1200000) || (extras.get("secs") instanceof Integer && extras.getInt("secs") > 1200))) return; String artist = extras.getString("artist"); String track = extras.getString("track"); long position = extras.containsKey("position") ? extras.getLong("position") : -1; if (extras.get("position") instanceof Double) position = Double.valueOf(extras.getDouble("position")).longValue(); boolean isPlaying = extras.getBoolean("playing", true); if (intent.getAction().equals("com.amazon.mp3.metachanged")) { artist = extras.getString("com.amazon.mp3.artist"); track = extras.getString("com.amazon.mp3.track"); } else if (intent.getAction().equals("com.spotify.music.metadatachanged")) isPlaying = spotifyPlaying; else if (intent.getAction().equals("com.spotify.music.playbackstatechanged")) spotifyPlaying = isPlaying; if ((artist == null || "".equals(artist)) //Could be problematic || (track == null || "".equals(track) || track.startsWith("DTNS"))) // Ignore one of my favorite podcasts return; SharedPreferences current = context.getSharedPreferences("current_music", Context.MODE_PRIVATE); String currentArtist = current.getString("artist", ""); String currentTrack = current.getString("track", ""); SharedPreferences.Editor editor = current.edit(); editor.putString("artist", artist); editor.putString("track", track); editor.putLong("position", position); editor.putBoolean("playing", isPlaying); if (isPlaying) { long currentTime = System.currentTimeMillis(); editor.putLong("startTime", currentTime); } editor.apply(); autoUpdate = autoUpdate || sharedPref.getBoolean("pref_auto_refresh", false); int notificationPref = Integer.valueOf(sharedPref.getString("pref_notifications", "0")); if (autoUpdate && App.isActivityVisible()) { Intent internalIntent = new Intent("Broadcast"); internalIntent.putExtra("artist", artist).putExtra("track", track); LyricsViewFragment.sendIntent(context, internalIntent); forceAutoUpdate(false); } SQLiteDatabase db = new DatabaseHelper(context).getReadableDatabase(); boolean inDatabase = DatabaseHelper.presenceCheck(db, new String[] { artist, track, artist, track }); db.close(); if (notificationPref != 0 && isPlaying && (inDatabase || OnlineAccessVerifier.check(context))) { Intent activityIntent = new Intent("com.geecko.QuickLyric.getLyrics").putExtra("TAGS", new String[] { artist, track }); Intent wearableIntent = new Intent("com.geecko.QuickLyric.SEND_TO_WEARABLE").putExtra("artist", artist) .putExtra("track", track); PendingIntent openAppPending = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent wearablePending = PendingIntent.getBroadcast(context, 8, wearableIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(R.drawable.ic_watch, context.getString(R.string.wearable_prompt), wearablePending).build(); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context); NotificationCompat.Builder wearableNotifBuilder = new NotificationCompat.Builder(context); if ("0".equals(sharedPref.getString("pref_theme", "0"))) notifBuilder.setColor(context.getResources().getColor(R.color.primary)); notifBuilder.setSmallIcon(R.drawable.ic_notif).setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setGroupSummary(true); wearableNotifBuilder.setSmallIcon(R.drawable.ic_notif) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setOngoing(false).setGroupSummary(false) .extend(new NotificationCompat.WearableExtender().addAction(wearableAction)); if (notificationPref == 2) { notifBuilder.setOngoing(true).setPriority(-2); // Notification.PRIORITY_MIN } else notifBuilder.setPriority(-1); // Notification.PRIORITY_LOW Notification notif = notifBuilder.build(); Notification wearableNotif = wearableNotifBuilder.build(); if (notificationPref == 2) notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; else notif.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManagerCompat.from(context).notify(0, notif); try { context.getPackageManager().getPackageInfo("com.google.android.wearable.app", PackageManager.GET_META_DATA); NotificationManagerCompat.from(context).notify(8, wearableNotif); } catch (PackageManager.NameNotFoundException ignored) { } } else if (track.equals(current.getString("track", ""))) NotificationManagerCompat.from(context).cancel(0); }
From source file:dk.dr.radio.afspilning.AfspillerIkonOgNotifikation.java
@SuppressLint("NewApi") public static Notification lavNotification(Context ctx) { String kanalNavn = ""; try {//from w w w .j av a 2s.c o m kanalNavn = DRData.instans.afspiller.getLydkilde().getKanal().navn; } catch (Exception e) { Log.rapporterFejl(e); } // TODO fjern try-catch efter nogle mneder i drift. 9. okt 2014 NotificationCompat.Builder b = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.dr_notifikation) .setContentTitle(ctx.getString(R.string.dr_radio)).setContentText(kanalNavn).setOngoing(true) .setAutoCancel(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setPriority(1001) // holder den verst .setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, Hovedaktivitet.class), 0)); // PendingIntent er til at pege p aktiviteten der skal startes hvis // brugeren vlger notifikationen b.setContent( AfspillerIkonOgNotifikation.lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_lille)); Notification notification = b.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // A notification's big view appears only when the notification is expanded, // which happens when the notification is at the top of the notification drawer, // or when the user expands the notification with a gesture. // Expanded notifications are available starting with Android 4.1. notification.bigContentView = AfspillerIkonOgNotifikation .lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_stor); } notification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.PRIORITY_HIGH | Notification.FLAG_FOREGROUND_SERVICE); return notification; }
From source file:org.droidkit.app.UpdateService.java
private void notifyDownloading(String json) { Intent intent = new Intent(this, UpdateActivity.class); intent.putExtra("downloading", true); intent.putExtra("json", json); String desc = "Downloading " + getString(getApplicationInfo().labelRes); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0); Notification n = new Notification(android.R.drawable.stat_sys_download, "Downloading update...", System.currentTimeMillis()); n.flags = Notification.FLAG_ONGOING_EVENT; n.contentIntent = pending;/* w ww . ja va2s . c om*/ RemoteViews view = new RemoteViews(getPackageName(), Resources.getId(this, "update_notification", Resources.TYPE_LAYOUT)); view.setTextViewText(Resources.getId(this, "update_title_text", Resources.TYPE_ID), desc); view.setProgressBar(Resources.getId(this, "update_progress_bar", Resources.TYPE_ID), 100, 0, true); view.setImageViewResource(Resources.getId(this, "update_notif_icon", Resources.TYPE_ID), android.R.drawable.stat_sys_download); n.contentView = view; mNotificationManager.notify("Downloading update...", UPDATE_DOWNLOADING_ID, n); }
From source file:io.github.carlorodriguez.alarmon.NotificationService.java
@Override public void onCreate() { super.onCreate(); firingAlarms = new LinkedList<>(); // Access to in-memory and persistent data structures. service = new AlarmClockServiceBinder(getApplicationContext()); service.bind();/*from w w w. j a v a2 s. c o m*/ db = new DbAccessor(getApplicationContext()); // Setup audio. MediaSingleton.INSTANCE.useContext(getApplicationContext()); // Setup notification bar. manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Use the notification activity explicitly in this intent just in case the // activity can't be viewed via the root activity. Intent intent = new Intent(getApplicationContext(), ActivityAlarmNotification.class); notificationActivity = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); // Setup a self-scheduling event loops. handler = new Handler(); volumeIncreaseCallback = new VolumeIncreaser(); soundCheck = new Runnable() { @Override public void run() { // Some sound should always be playing. MediaSingleton.INSTANCE.ensureSound(); long next = AlarmUtil.millisTillNextInterval(AlarmUtil.Interval.SECOND); handler.postDelayed(soundCheck, next); } }; notificationBlinker = new Runnable() { @Override public void run() { String notifyText; try { AlarmInfo info = db.readAlarmInfo(currentAlarmId()); notifyText = (info == null || info.getName() == null) ? "" : info.getName(); if (notifyText.equals("") && info != null) { notifyText = info.getTime().localizedString(getApplicationContext()); } } catch (NoAlarmsException e) { return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); Notification notification = builder.setContentIntent(notificationActivity) .setSmallIcon(R.drawable.ic_stat_notify_alarm).setContentTitle(notifyText) .setContentText("") .setColor(ContextCompat.getColor(getApplicationContext(), R.color.notification_color)) .build(); notification.flags |= Notification.FLAG_ONGOING_EVENT; manager.notify(AlarmClockService.NOTIFICATION_BAR_ID, notification); long next = AlarmUtil.millisTillNextInterval(AlarmUtil.Interval.SECOND); handler.postDelayed(notificationBlinker, next); } }; autoCancel = new Runnable() { @Override public void run() { try { acknowledgeCurrentNotification(0); } catch (NoAlarmsException e) { return; } Intent notifyActivity = new Intent(getApplicationContext(), ActivityAlarmNotification.class); notifyActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notifyActivity.putExtra(ActivityAlarmNotification.TIMEOUT_COMMAND, true); startActivity(notifyActivity); } }; }
From source file:org.chirpradio.mobile.PlaybackService.java
private void setNotification(String title, String message) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); CharSequence tickerText = message; long when = System.currentTimeMillis(); int icon = R.drawable.icon; Notification notification = new Notification(icon, tickerText, when); notification.flags = Notification.FLAG_ONGOING_EVENT; Context context = getApplicationContext(); CharSequence contentTitle = title; CharSequence contentText = message; Intent notificationIntent = new Intent(this, Playing.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(CHIRP_ID, notification); }