List of usage examples for android.app Notification CATEGORY_SERVICE
String CATEGORY_SERVICE
To view the source code for android.app Notification CATEGORY_SERVICE.
Click Source Link
From source file:org.runnerup.util.NotificationCompat.java
public static void setCategory(Builder builder) { if (Build.VERSION.SDK_INT >= 21) { builder.setCategory(Notification.CATEGORY_SERVICE); } }
From source file:org.traccar.client.TrackingService.java
private static Notification createNotification(Context context) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainApplication.PRIMARY_CHANNEL).setSmallIcon(R.drawable.ic_stat_notify) .setPriority(NotificationCompat.PRIORITY_LOW).setCategory(Notification.CATEGORY_SERVICE); Intent intent;/*from w w w. j av a 2 s . c o m*/ if (!BuildConfig.HIDDEN_APP) { intent = new Intent(context, MainActivity.class); builder.setContentTitle(context.getString(R.string.settings_status_on_summary)) .setTicker(context.getString(R.string.settings_status_on_summary)) .setColor(ContextCompat.getColor(context, R.color.primary_dark)); } else { intent = new Intent(android.provider.Settings.ACTION_SETTINGS); } builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)); return builder.build(); }
From source file:org.site_monitor.util.NotificationUtil.java
/** * Pre builds notification./*from ww w. j a v a 2 s . c o m*/ * * @param context * @param title * @param text * @param pendingIntent */ public static NotificationCompat.Builder build(Context context, String title, String text, PendingIntent pendingIntent) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setSmallIcon(R.drawable.ic_app); if (!BuildConfig.DEBUG) { notificationBuilder.setColor(context.getResources().getColor(R.color.primary)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setCategory(Notification.CATEGORY_SERVICE); } notificationBuilder.setContentTitle(title).setContentText(text); notificationBuilder.setAutoCancel(true); String ringtonePath = preferences.getString(PrefSettingsActivity.NOTIFICATIONS_RINGTONE, null); Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (ringtonePath != null && !ringtonePath.isEmpty()) { ringtoneUri = Uri.parse(ringtonePath); } notificationBuilder.setSound(ringtoneUri); String colorString = preferences.getString(PrefSettingsActivity.NOTIFICATION_LIGHT_COLOR, Color.WHITE + ""); int color = Integer.valueOf(colorString); notificationBuilder.setLights(color, TimeUtil._1_SEC_INT * 2, TimeUtil._1_SEC_INT * 10); if (preferences.getBoolean(PrefSettingsActivity.NOTIFICATIONS_VIBRATE, false)) { long[] pattern = { NotificationCompat.DEFAULT_VIBRATE * TimeUtil.SEC_2_MILLISEC }; notificationBuilder.setVibrate(pattern); } notificationBuilder.setContentIntent(pendingIntent); return notificationBuilder; }
From source file:org.linphone.compatibility.ApiTwentyOnePlus.java
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent, int priority) { Notification notif;//from ww w .j a v a 2s . co m if (largeIcon != null) { notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(message) .setSmallIcon(icon, level).setLargeIcon(largeIcon).setContentIntent(intent) .setCategory(Notification.CATEGORY_SERVICE).setVisibility(Notification.VISIBILITY_SECRET) .setPriority(priority).build(); } else { notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(message) .setSmallIcon(icon, level).setContentIntent(intent).setCategory(Notification.CATEGORY_SERVICE) .setVisibility(Notification.VISIBILITY_SECRET).setPriority(priority).build(); } return notif; }
From source file:com.stanleyidesis.quotograph.api.controller.LWQNotificationControllerImpl.java
@Override public void postNewWallpaperNotification() { dismissWallpaperGenerationFailureNotification(); final LWQWallpaperController wallpaperController = LWQWallpaperControllerHelper.get(); // Compress background to reasonable Square size final Bitmap backgroundImage = wallpaperController.getBackgroundImage(); if (backgroundImage == null) { return;/* ww w .jav a2 s .com*/ } final Bitmap notificationBitmap = chopToCenterSquare(backgroundImage); Context context = LWQApplication.get(); // Establish basic options NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setAutoCancel(true); notificationBuilder.setCategory(Notification.CATEGORY_SERVICE); notificationBuilder.setColor(LWQApplication.get().getResources().getColor(R.color.palette_A100)); notificationBuilder.setContentInfo(wallpaperController.getAuthor()); notificationBuilder.setContentTitle(context.getString(R.string.new_quotograph)); notificationBuilder.setContentText(String.format("\"%s\"", wallpaperController.getQuote())); notificationBuilder.setLights(LWQApplication.get().getResources().getColor(R.color.palette_A100), 500, 500); notificationBuilder.setLargeIcon(notificationBitmap); notificationBuilder.setOngoing(false); notificationBuilder.setShowWhen(false); notificationBuilder.setSmallIcon(R.mipmap.ic_stat); notificationBuilder.setTicker(String.format("New quote from %s", wallpaperController.getAuthor())); notificationBuilder.setWhen(System.currentTimeMillis()); // Create BigTextStyle NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.bigText(wallpaperController.getQuote()); bigTextStyle.setBigContentTitle(wallpaperController.getAuthor()); bigTextStyle.setSummaryText(context.getString(R.string.new_quotograph)); notificationBuilder.setStyle(bigTextStyle); // Set Content Intent Intent mainIntent = new Intent(context, LWQActivateActivity.class); mainIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); notificationBuilder .setContentIntent(PendingIntent.getActivity(context, uniqueRequestCode++, mainIntent, 0)); // Add Share Action Intent shareIntent = new Intent(context, LWQReceiver.class); shareIntent.setAction(context.getString(R.string.action_share)); shareIntent.setData(Uri.parse(AnalyticsUtils.URI_SHARE_SOURCE_NOTIFICATION)); final PendingIntent shareBroadcast = PendingIntent.getBroadcast(context, uniqueRequestCode++, shareIntent, 0); final NotificationCompat.Action shareAction = new NotificationCompat.Action.Builder(R.mipmap.ic_share_white, context.getString(R.string.share), shareBroadcast).build(); notificationBuilder.addAction(shareAction); // Add save to disk Intent saveToDiskIntent = new Intent(context, LWQSaveWallpaperActivity.class); saveToDiskIntent.setData(Uri.parse(AnalyticsUtils.URI_SAVE_SOURCE_NOTIFICATION)); final PendingIntent saveToDiskActivity = PendingIntent.getActivity(context, uniqueRequestCode++, saveToDiskIntent, 0); final NotificationCompat.Action saveToDiskAction = new NotificationCompat.Action.Builder( R.mipmap.ic_save_white, context.getString(R.string.save_to_disk), saveToDiskActivity).build(); notificationBuilder.addAction(saveToDiskAction); // Add Skip Action Intent skipIntent = new Intent(context, LWQReceiver.class); skipIntent.setAction(context.getString(R.string.action_change_wallpaper)); // Track where the skip originated skipIntent.setData(Uri.parse(AnalyticsUtils.URI_CHANGE_SOURCE_NOTIFICATION)); final PendingIntent skipBroadcast = PendingIntent.getBroadcast(context, uniqueRequestCode++, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Action skipAction = new NotificationCompat.Action.Builder( R.mipmap.ic_skip_next_white, context.getString(R.string.skip), skipBroadcast).build(); notificationBuilder.addAction(skipAction); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIF_ID_PRIMARY, notificationBuilder.build()); notificationBitmap.recycle(); }
From source file:com.oceansky.yellow.service.ServiceNotification.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void buildNotification() { if (mCurrentSong == null) { return;//from w w w .j a va 2 s .c o m } buildRemoteViews(); buildBaseNotification(); // And get the notification object mNotification = mBuilder.build(); // Add the expanded controls mNotification.bigContentView = mExpandedTemplate; if (Utils.hasLollipop()) { mNotification.category = Notification.CATEGORY_SERVICE; mNotification.visibility = Notification.VISIBILITY_PUBLIC; } // Update fields final ProviderAggregator aggregator = ProviderAggregator.getDefault(); if (mCurrentSong != null) { if (mCurrentSong.isLoaded()) { final Artist artist = mCurrentSong.getArtist() != null ? aggregator.retrieveArtist(mCurrentSong.getArtist(), mCurrentSong.getProvider()) : null; final Album album = mCurrentSong.getAlbum() != null ? aggregator.retrieveAlbum(mCurrentSong.getAlbum(), mCurrentSong.getProvider()) : null; // Song title mBaseTemplate.setTextViewText(R.id.tvNotifLineOne, mCurrentSong.getTitle()); mExpandedTemplate.setTextViewText(R.id.tvNotifLineOne, mCurrentSong.getTitle()); if (artist != null && artist.getName() != null && !artist.getName().isEmpty()) { // Artist name mBaseTemplate.setTextViewText(R.id.tvNotifLineTwo, artist.getName()); mExpandedTemplate.setTextViewText(R.id.tvNotifLineTwo, artist.getName()); } else { mBaseTemplate.setTextViewText(R.id.tvNotifLineTwo, null); mExpandedTemplate.setTextViewText(R.id.tvNotifLineTwo, null); } if (album != null && album.getName() != null && !album.getName().isEmpty()) { // Album name mExpandedTemplate.setTextViewText(R.id.tvNotifLineThree, album.getName()); } else { mExpandedTemplate.setTextViewText(R.id.tvNotifLineThree, null); } } else { mBuilder.setContentTitle(getString(R.string.loading)); } } if (mShowPlayAction) { mBaseTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_play); mExpandedTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_play); } else { mBaseTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_pause); mExpandedTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_pause); } if (mHasNext) { mBaseTemplate.setViewVisibility(R.id.btnNotifNext, View.VISIBLE); mExpandedTemplate.setViewVisibility(R.id.btnNotifNext, View.VISIBLE); } else { mBaseTemplate.setViewVisibility(R.id.btnNotifNext, View.GONE); mExpandedTemplate.setViewVisibility(R.id.btnNotifNext, View.GONE); } if (mCurrentArt != null && !mCurrentArt.getBitmap().isRecycled()) { mBaseTemplate.setImageViewBitmap(R.id.ivAlbumArt, mCurrentArt.getBitmap()); mExpandedTemplate.setImageViewBitmap(R.id.ivAlbumArt, mCurrentArt.getBitmap()); } else { mBaseTemplate.setImageViewResource(R.id.ivAlbumArt, R.drawable.album_placeholder); mExpandedTemplate.setImageViewResource(R.id.ivAlbumArt, R.drawable.album_placeholder); } // Post update if (mListener != null) { mListener.onNotificationChanged(this); } }
From source file:com.fastbootmobile.encore.service.ServiceNotification.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void buildNotification() { if (mCurrentSong == null) { return;/*from w ww . j av a 2 s .c o m*/ } buildRemoteViews(); buildBaseNotification(); // And get the notification object mNotification = mBuilder.build(); // Add the expanded controls mNotification.bigContentView = mExpandedTemplate; if (Utils.hasLollipop()) { mNotification.category = Notification.CATEGORY_SERVICE; } // Update fields final ProviderAggregator aggregator = ProviderAggregator.getDefault(); if (mCurrentSong != null) { if (mCurrentSong.isLoaded()) { final Artist artist = mCurrentSong.getArtist() != null ? aggregator.retrieveArtist(mCurrentSong.getArtist(), mCurrentSong.getProvider()) : null; final Album album = mCurrentSong.getAlbum() != null ? aggregator.retrieveAlbum(mCurrentSong.getAlbum(), mCurrentSong.getProvider()) : null; // Song title mBaseTemplate.setTextViewText(R.id.tvNotifLineOne, mCurrentSong.getTitle()); mExpandedTemplate.setTextViewText(R.id.tvNotifLineOne, mCurrentSong.getTitle()); if (artist != null && artist.getName() != null && !artist.getName().isEmpty()) { // Artist name mBaseTemplate.setTextViewText(R.id.tvNotifLineTwo, artist.getName()); mExpandedTemplate.setTextViewText(R.id.tvNotifLineTwo, artist.getName()); } else { mBaseTemplate.setTextViewText(R.id.tvNotifLineTwo, null); mExpandedTemplate.setTextViewText(R.id.tvNotifLineTwo, null); } if (album != null && album.getName() != null && !album.getName().isEmpty()) { // Album name mExpandedTemplate.setTextViewText(R.id.tvNotifLineThree, album.getName()); } else { mExpandedTemplate.setTextViewText(R.id.tvNotifLineThree, null); } } else { mBuilder.setContentTitle(getString(R.string.loading)); } } if (mShowPlayAction) { mBaseTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_play); mExpandedTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_play); } else { mBaseTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_pause); mExpandedTemplate.setImageViewResource(R.id.btnNotifPlayPause, R.drawable.ic_notif_pause); } if (mHasNext) { mBaseTemplate.setViewVisibility(R.id.btnNotifNext, View.VISIBLE); mExpandedTemplate.setViewVisibility(R.id.btnNotifNext, View.VISIBLE); } else { mBaseTemplate.setViewVisibility(R.id.btnNotifNext, View.GONE); mExpandedTemplate.setViewVisibility(R.id.btnNotifNext, View.GONE); } if (mCurrentArt != null && !mCurrentArt.getBitmap().isRecycled()) { mBaseTemplate.setImageViewBitmap(R.id.ivAlbumArt, mCurrentArt.getBitmap()); mExpandedTemplate.setImageViewBitmap(R.id.ivAlbumArt, mCurrentArt.getBitmap()); } else { mBaseTemplate.setImageViewResource(R.id.ivAlbumArt, R.drawable.album_placeholder); mExpandedTemplate.setImageViewResource(R.id.ivAlbumArt, R.drawable.album_placeholder); } // Post update if (mListener != null) { mListener.onNotificationChanged(this); } }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.SwitcherService.java
private void setForegroundNotification() { Intent startupIntent = new Intent(this, MainActivity.class); startupIntent.setAction(Intent.ACTION_MAIN); startupIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent startupPendingIntent = PendingIntent.getActivity(this, 0, startupIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentIntent(startupPendingIntent) .setContentTitle(getString(R.string.switcher_service_background_service)) .setPriority(Notification.PRIORITY_MIN); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_SERVICE); }// ww w .ja v a2 s .com startForeground(NOTIFICATION_ID, builder.build()); }
From source file:com.cyanogenmod.settings.otgtoggle.UsbDeviceMonitorService.java
void updateNotification(boolean connected, int mode) { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (!connected) { nm.cancel(OTG_NOTIFICATION_ID);/*w w w .j ava 2s. co m*/ return; } final Intent clickIntent = new Intent(this, OtgModeChooserActivity.class) .putExtra(OtgModeChooserActivity.EXTRA_CURRENT_MODE, getDetectionMode()); final PendingIntent clickPi = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); final int titleResId; switch (mode) { case MODE_HEADSET: titleResId = R.string.connection_notification_title_headset; break; case MODE_OTG: titleResId = R.string.connection_notification_title_otg; break; default: titleResId = R.string.connection_notification_title_detect; break; } final Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_headset_notification).setLocalOnly(true).setOngoing(true).setWhen(0) .setDefaults(0).setShowWhen(false).setCategory(Notification.CATEGORY_SERVICE) .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_MIN) .setColor(getResources().getColor(com.android.internal.R.color.system_notification_accent_color)) .setContentTitle(getString(titleResId)) .setContentText(getString(R.string.connection_notification_text)).setContentIntent(clickPi); nm.notify(OTG_NOTIFICATION_ID, builder.build()); }
From source file:com.stanleyidesis.quotograph.api.controller.LWQNotificationControllerImpl.java
@Override public void postWallpaperGenerationFailureNotification() { // Two actions: Network Settings & Try Again LWQApplication context = LWQApplication.get(); // Establish basic options NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setAutoCancel(true); notificationBuilder.setCategory(/*from ww w .ja va 2 s . c o m*/ Build.VERSION.SDK_INT > 21 ? Notification.CATEGORY_ERROR : Notification.CATEGORY_SERVICE); notificationBuilder.setColor(LWQApplication.get().getResources().getColor(R.color.palette_A100)); notificationBuilder.setContentInfo(context.getString(R.string.app_name)); notificationBuilder.setContentTitle(context.getString(R.string.notification_generation_failure_title)); notificationBuilder.setContentText(context.getString(R.string.notification_generation_failure_content)); notificationBuilder.setLights(LWQApplication.get().getResources().getColor(R.color.palette_A100), 500, 500); notificationBuilder.setTicker(context.getString(R.string.notification_generation_failure_ticker)); notificationBuilder.setOngoing(false); notificationBuilder.setShowWhen(true); notificationBuilder.setLocalOnly(true); notificationBuilder.setPriority(NotificationCompat.PRIORITY_MIN); notificationBuilder.setSmallIcon(android.R.drawable.stat_notify_error); notificationBuilder.setWhen(System.currentTimeMillis()); // Create BigTextStyle NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(context.getString(R.string.notification_generation_failure_title)); bigTextStyle.bigText(context.getString(R.string.notification_generation_failure_content)); notificationBuilder.setStyle(bigTextStyle); // Add Settings Action Intent settingsIntent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); final PendingIntent settingsBroadcast = PendingIntent.getActivity(context, uniqueRequestCode++, settingsIntent, 0); final NotificationCompat.Action settingsAction = new NotificationCompat.Action.Builder( R.mipmap.ic_settings_white, context.getString(R.string.notification_generation_failure_action_settings), settingsBroadcast) .build(); notificationBuilder.addAction(settingsAction); // Add Skip Action Intent skipIntent = new Intent(context, LWQReceiver.class); skipIntent.setAction(context.getString(R.string.action_change_wallpaper)); skipIntent.setData(Uri.parse(AnalyticsUtils.URI_CHANGE_SOURCE_NOTIFICATION)); final PendingIntent skipBroadcast = PendingIntent.getBroadcast(context, uniqueRequestCode++, skipIntent, 0); final NotificationCompat.Action skipAction = new NotificationCompat.Action.Builder( R.mipmap.ic_refresh_white_36dp, context.getString(R.string.notification_generation_failure_action_try_again), skipBroadcast) .build(); notificationBuilder.addAction(skipAction); // Set Skip as main action notificationBuilder.setContentIntent(skipBroadcast); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIF_ID_GEN_FAILURE, notificationBuilder.build()); }