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:net.tac42.subtails.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String text = song.getArtist(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); // Set the album art. try {/*from w w w. j a v a 2 s . c o m*/ int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { contentView.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications contentView.setTextViewText(R.id.notification_title, title); contentView.setTextViewText(R.id.notification_artist, text); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { contentView.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { contentView.setTextColor(R.id.notification_artist, colors.getSecond()); } notification.contentView = contentView; Intent notificationIntent = new Intent(context, DownloadActivity.class); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); // Send the notification and put the service in the foreground. handler.post(new Runnable() { @Override public void run() { startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget SubtailsAppWidgetProvider.getInstance().notifyChange(context, downloadService, true); }
From source file:com.nbplus.push.PushService.java
/** * Configures service as a foreground service. A foreground service is a service that's doing * something the user is actively aware of (such as playing music), and must appear to the * user as a notification. That's why we create the notification here. *///from w w w. ja va 2 s .co m void setUpAsForeground() { // notification's layout mBuilder = new NotificationCompat.Builder(this); CharSequence ticker = getString(R.string.push_noti_body); int apiVersion = Build.VERSION.SDK_INT; mBuilder.setSmallIcon(R.drawable.ic_notification_push).setAutoCancel(false).setOngoing(true) .setContentTitle(getString(R.string.push_name)).setContentText(ticker) .setPriority(NotificationCompat.PRIORITY_MAX).setTicker(ticker); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_ONGOING_EVENT; mNotification.defaults |= Notification.DEFAULT_LIGHTS; startForeground(NOTIFICATION_ID, mNotification); }
From source file:com.plusot.senselib.SenseMain.java
@SuppressWarnings("deprecation") public void notifyMe() { String version = ""; try {/*from www . jav a 2s . c o m*/ PackageInfo info = Globals.appContext.getPackageManager() .getPackageInfo(Globals.appContext.getPackageName(), 0); version = " " + info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } Notification note = new Notification(SenseGlobals.notifyIcon, Globals.TAG + version, System.currentTimeMillis()); //String[] hints = Globals.appContext.getResources().getStringArray(R.array.hint_items); //String hint = hints[(int)(Math.random() * (hints.length - 1))]; PendingIntent intent = PendingIntent.getActivity(Globals.appContext, 0, new Intent(Globals.appContext, SenseGlobals.mainClass), 0); note.setLatestEventInfo(Globals.appContext, Globals.TAG + version, Globals.appContext.getString(R.string.hello), intent); //note.ledOnMS = 1000; //note.ledOffMS = 1000; //note.ledARGB = 0xFFFFFFFF; //note.tickerText = hint; //note.number=++noteCount; note.flags |= Notification.FLAG_ONGOING_EVENT; //note.vibrate=new long[] {20L, 50L}; noteManager.notify(NOTIFY_ME_ID, note); }
From source file:com.halseyburgund.rwframework.core.RWService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // intent will be null on restart! if (intent != null) { getSettingsFromIntent(intent);//from w w w . ja va 2s . co m } // create a pending intent to start the specified activity from the notification Intent ovIntent = new Intent(this, mNotificationActivity); mNotificationPendingIntent = PendingIntent.getActivity(this, 0, ovIntent, Intent.FLAG_ACTIVITY_NEW_TASK); // create a notification and move service to foreground mRwNotification = new Notification(mNotificationIconId, "Roundware Service Started", System.currentTimeMillis()); mRwNotification.number = 1; mRwNotification.flags = mRwNotification.flags | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; setNotificationText(""); startForeground(NOTIFICATION_ID, mRwNotification); // try to go on-line, this will attempt to get the configuration and tags manageSessionState(SessionState.ON_LINE); return Service.START_STICKY; }
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void showPlayingNotification(final Context context, Handler handler, MusicDirectory.Entry song) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, FragActivity.class), 0);//ww w. j a v a 2s .c o m String text = song.getArtist(); notification.setLatestEventInfo(context, title, text, contentIntent); // Send the notification. handler.post(new Runnable() { @Override public void run() { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DownloadService service = DownloadServiceImpl.getInstance(); if (service != null) { SubsonicAppWidgetProvider.getInstance().notifyChange(context, service, true); } }
From source file:github.daneren2005.dsub.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, 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()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, playing); notification.bigContentView = expandedContentView; }/*from w ww .j av a 2 s . com*/ RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, playing); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, DownloadActivity.class); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); handler.post(new Runnable() { @Override public void run() { downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void setNotification(boolean visible) { final String ACTION = "org.distantshoresmedia.translationkeyboard.SHOW"; final int ID = 1; String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); if (visible && mNotificationReceiver == null) { int icon = R.drawable.icon; CharSequence text = "Keyboard notification enabled."; long when = System.currentTimeMillis(); // TODO: clean this up? mNotificationReceiver = new NotificationReceiver(this); final IntentFilter pFilter = new IntentFilter(ACTION); registerReceiver(mNotificationReceiver, pFilter); Intent notificationIntent = new Intent(ACTION); PendingIntent contentIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent, 0);/*from w w w . j a va 2 s . c o m*/ //PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); String title = "Show translationKeyboard Keyboard"; String body = "Select this to open the keyboard. Disable in settings."; // Notification notification = new Notification(icon, text, when); // // notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; // notification.setLatestEventInfo(getApplicationContext(), title, body, contentIntent); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); builder.setContentIntent(contentIntent).setSmallIcon(icon) .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), icon)) .setTicker(body).setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentTitle(title) .setContentText(body); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; mNotificationManager.notify(ID, notification); } else if (mNotificationReceiver != null) { mNotificationManager.cancel(ID); unregisterReceiver(mNotificationReceiver); mNotificationReceiver = null; } }
From source file:com.umundus.service.NCallServiceOld.java
public void onCreate() { Log.d(TAG, "[*]Service-onCreate"); super.onCreate(); IntentFilter filter = new IntentFilter(ACTION_START_PATTERN_SEND_DATA); filter.addAction(ACTION_END_PATTERN_SEND_DATA); registerReceiver(mBroadcastReceiver, filter); int myID = 1234; Intent intent = new Intent(this, NCallServiceOld.class); //PendingIntent pendIntent = PendingIntent.getActivity(this, 0, bindIntent, 0); PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_NO_CREATE); Notification notice = new Notification.Builder(this).setContentTitle("(Rang)") .setContentText("(Rang)? .").setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)).setOngoing(true) .setContentIntent(pi).build(); notice.flags |= Notification.FLAG_NO_CLEAR; notice.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(myID, notice);//from ww w. ja v a 2s. c o m AlarmManager al = (AlarmManager) this.getSystemService(this.ALARM_SERVICE); al.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000 * 15, pi); }
From source file:com.geryon.ocraa.MusicService.java
/** * Configures service as a foreground service. A foreground service is a service that's doing * something the user is actively aware of (such as playing music), and must appear to the * user as a notification. That's why we create the notification here. *//*from w w w .java 2 s . c o m*/ void setUpAsForeground(String text) { PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), OCRAA.class), PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification(); mNotification.tickerText = text; mNotification.icon = R.drawable.ic_stat_playing; mNotification.flags |= Notification.FLAG_ONGOING_EVENT; mNotification.setLatestEventInfo(getApplicationContext(), "RandomMusicPlayer", text, pi); startForeground(NOTIFICATION_ID, mNotification); }