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:com.islandmonkey.eqeq.EQEQIsRunning.java
/** * Shows the notification, or updates a previously shown notification of * this type, with the given parameters. * @see #cancel(Context)//w w w .j a va 2 s.c o m */ public static void notify(final Context context, final int number) { final Resources res = context.getResources(); // This image is used as the notification's large icon (thumbnail). final Bitmap picture = BitmapFactory.decodeResource(res, R.drawable.eqeqicon); final String title = res.getString(R.string.eqeq_is_running_notification_title); final String text = res.getString(R.string.eqeq_is_running_notification_text); final Intent notificationIntent = new Intent(context, EQActivity.class); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) // Set appropriate defaults for the notification light, sound, // and vibration. .setDefaults(Notification.FLAG_ONGOING_EVENT) // Set required fields, including the small icon, the // notification title, and text. .setSmallIcon(R.drawable.eqeqicon).setContentTitle(title).setContentText(text) // All fields below this line are optional. // Use a default priority (recognised on devices running Android // 4.1 or later) // Provide a large icon, shown with the notification in the // notification drawer on devices running Android 3.0 or later. .setLargeIcon(picture) // Set the pending intent to be initiated when the user touches // the notification. .setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)) // This is an ongoing notification .setOngoing(true) // Automatically dismiss the notification when it is touched. .setAutoCancel(false); notify(context, builder.build()); }
From source file:com.monkey.entonado.AlarmReciever.java
@Override public void onReceive(Context context, Intent intent) { System.out.println("llego a recieve ------------------"); // TODO Auto-generated method stub Intent in = new Intent(context, MainActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(context, 1994, in, PendingIntent.FLAG_ONE_SHOT); NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); NotificationCompat.Builder not = new NotificationCompat.Builder(context); not.setSmallIcon(android.R.drawable.ic_popup_sync).setAutoCancel(true) .setContentTitle("Ya han pasado 20 minutos").setContentText("Toca para pedir ms canciones") .setTicker("Ya puedes mandar canciones!").setContentIntent(pi); Notification noti = not.build(); noti.flags |= Notification.FLAG_ONGOING_EVENT; manager.notify(MainActivity.TAG, 0, noti); }
From source file:org.telegram.kleegram.autoanswer.AutoAnswerNotifier.java
private void enableNotification() { // Intent to call to turn off AutoAnswer Intent notificationIntent = new Intent(mContext, AutoAnswerPreferenceActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0); // Create the notification Notification notification = new Notification(R.drawable.stat_sys_autoanswer, null, 0); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); notification = builder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_sys_autoanswer) .setAutoCancel(true).setContentTitle(mContext.getString(R.string.notification_title)) .setContentText(mContext.getString(R.string.notification_text)).build(); mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.paranoid.halo.utils.Notes.java
public static void showNoteNotification(Context context, NotificationManager notificationManager, int id, String note) {// ww w . jav a2 s.c om Intent intent = new Intent(context, NotesActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); NotificationCompat.Builder ext_builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_add).setContentIntent(pendingIntent).setContentTitle(note); Notification notif = ext_builder.build(); notif.flags |= Notification.FLAG_ONGOING_EVENT; notif.priority = Notification.PRIORITY_MIN; notif.tickerText = note; notificationManager.notify(id, notif); }
From source file:github.daneren2005.dsub.util.Notifications.java
public static void showPlayingNotification(final Context context, final DownloadService downloadService, final Handler handler, MusicDirectory.Entry song) { // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis()); final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (playing) { notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; }/* w w w. j av a 2 s .com*/ boolean remote = downloadService.isRemoteEnabled(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, true, playing, remote); notification.bigContentView = expandedContentView; notification.priority = Notification.PRIORITY_HIGH; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.visibility = Notification.VISIBILITY_PUBLIC; } RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, false, playing, remote); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); playShowing = true; if (downloadForeground && downloadShowing) { downloadForeground = false; handler.post(new Runnable() { @Override public void run() { downloadService.stopForeground(true); showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); } }); } else { handler.post(new Runnable() { @Override public void run() { if (playing) { downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); } else { playShowing = false; persistentPlayingShowing = true; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); downloadService.stopForeground(false); notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); } } }); } // Update widget DSubWidgetProvider.notifyInstances(context, downloadService, playing); }
From source file:info.bits.phoneastablet.utils.NotificationHandler.java
/** * Shows the notification at the notification area. *//* ww w. j a v a 2 s. c o m*/ public void enableNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setTicker(context.getResources().getString(R.string.notification_ticker)).setAutoCancel(false) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.notification_private_text)) .setSmallIcon(R.drawable.ic_launcher); nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT; RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); //set the button listeners setListeners(contentView); notification.contentView = contentView; nm.notify(NOTIFICATION_ID, notification); }
From source file:com.aniruddhc.acemusic.player.Services.AutoFetchAlbumArtService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { //Launch a notification to set the service as a foreground service. builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentTitle(getResources().getString(R.string.downloading_missing_cover_art)); builder.setTicker(getResources().getString(R.string.downloading_missing_cover_art)); builder.setContentText(null);//w w w. j a va 2 s . c o m notification = builder.build(); notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(NOTIFICATION_ID, notification); //Call the AsyncTask that checks for missing art and downloads them. AsyncAutoGetAlbumArtTask task = new AsyncAutoGetAlbumArtTask(mContext, SettingsActivity____.mSettingsActivity); task.execute(); return START_STICKY; }
From source file:dk.dr.radio.afspilning.HoldAppIHukommelsenService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d("AfspillerService onStartCommand(" + intent + " " + flags + " " + startId); String kanalNavn = intent == null ? null : intent.getStringExtra("kanalNavn"); if (kanalNavn == null) kanalNavn = ""; NotificationCompat.Builder b = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notifikation_ikon).setContentTitle("DR Radio").setContentText(kanalNavn) .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, Afspilning_akt.class), 0)) .setContent(AfspillerWidget.lavRemoteViews()); //notification = new Notification(R.drawable.notifikation_ikon, null, 0); Notification notification = b.build(); // PendingIntent er til at pege p aktiviteten der skal startes hvis brugeren vlger notifikationen //notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Afspilning_akt.class), 0); notification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT); //notification.setLatestEventInfo(this, "Radio", kanalNavn, notification.contentIntent); startForeground(NOTIFIKATION_ID, notification); return START_STICKY; }
From source file:uk.co.jarofgreen.cityoutdoors.Service.SendFeatureContentOrReportService.java
protected void onHandleIntent(Intent intent) { OurApplication ourApp = (OurApplication) getApplication(); if (ourApp.hasMoreToUpload()) { BaseUploadContentOrReport upload = ourApp.getNextToUpload(); int featureID = upload.hasFeatureID() ? upload.getFeatureID() : -1; // ---------- Start Ongoing Notification int icon = R.drawable.notification; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, "Sending", when); Intent notificationIntent = new Intent(this, SendFeatureContentOrReportProgressActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(getApplicationContext(), getString(R.string.send_feature_content_or_report_service_notification_content_title), getString(R.string.send_feature_content_or_report_service_notification_content_text), contentIntent);/* w w w .ja va 2s . c o m*/ notification.flags = Notification.DEFAULT_SOUND; notification.flags |= Notification.DEFAULT_VIBRATE; notification.flags |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_ONGOING_EVENT; NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(SendFeatureContentOrReportService.NOTIFICATION_ID, notification); //------------ Send if (upload instanceof UploadFeatureContent) { sendFeatureContent((UploadFeatureContent) upload); } else if (upload instanceof UploadFeatureReport) { sendFeatureReport((UploadFeatureReport) upload); } //----------- Remove from que ourApp.removeUploadFromQue(upload); // ---------- End Ongoing Notification if (!ourApp.hasMoreToUpload()) { mNotificationManager.cancel(SendFeatureContentOrReportService.NOTIFICATION_ID); } } }
From source file:github.popeen.dsub.util.Notifications.java
public static void showPlayingNotification(final Context context, final DownloadService downloadService, final Handler handler, MusicDirectory.Entry song) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { getPlayingNotificationChannel(context); }/*from ww w . java2 s . co m*/ // Set the icon, scrolling text and timestamp final Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_notify_playing).setTicker(song.getTitle()) .setWhen(System.currentTimeMillis()).setChannelId("now-playing-channel").build(); final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (playing) { notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; } boolean remote = downloadService.isRemoteEnabled(); boolean isSingle = downloadService.isCurrentPlayingSingle(); boolean shouldFastForward = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, true, playing, remote, isSingle, shouldFastForward); notification.bigContentView = expandedContentView; notification.priority = Notification.PRIORITY_HIGH; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.visibility = Notification.VISIBILITY_PUBLIC; if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_HEADS_UP_NOTIFICATION, false) && !UpdateView.hasActiveActivity()) { notification.vibrate = new long[0]; } } RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, false, playing, remote, isSingle, shouldFastForward); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); playShowing = true; if (downloadForeground && downloadShowing) { downloadForeground = false; handler.post(new Runnable() { @Override public void run() { stopForeground(downloadService, true); showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); try { startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification); } catch (Exception e) { Log.e(TAG, "Failed to start notifications after stopping foreground download"); } } }); } else { handler.post(new Runnable() { @Override public void run() { if (playing) { try { startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification); } catch (Exception e) { Log.e(TAG, "Failed to start notifications while playing"); } } else { playShowing = false; persistentPlayingShowing = true; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); stopForeground(downloadService, false); try { notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); } catch (Exception e) { Log.e(TAG, "Failed to start notifications while paused"); } } } }); } // Update widget DSubWidgetProvider.notifyInstances(context, downloadService, playing); }