List of usage examples for android.widget RemoteViews setImageViewBitmap
public void setImageViewBitmap(int viewId, Bitmap bitmap)
From source file:org.physical_web.physicalweb.UriBeaconDiscoveryService.java
private void updateSummaryNotificationRemoteViewsSecondBeacon(String url, RemoteViews remoteViews) { MetadataResolver.UrlMetadata urlMetadata_secondBeacon = mUrlToUrlMetadata.get(url); if (urlMetadata_secondBeacon != null) { String title = mUrlToUrlMetadata.get(url).title; String description = mUrlToUrlMetadata.get(url).description; Bitmap icon = mUrlToUrlMetadata.get(url).icon; remoteViews.setImageViewBitmap(R.id.icon_secondBeacon, icon); remoteViews.setTextViewText(R.id.title_secondBeacon, title); remoteViews.setTextViewText(R.id.url_secondBeacon, url); remoteViews.setTextViewText(R.id.description_secondBeacon, description); // Recolor notifications to have light text for non-Lollipop devices if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) { remoteViews.setTextColor(R.id.title_secondBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR); remoteViews.setTextColor(R.id.url_secondBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR); remoteViews.setTextColor(R.id.description_secondBeacon, NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR); }//from ww w. j a v a 2s. c om // Create an intent that will open the browser to the beacon's url // if the user taps the notification PendingIntent pendingIntent = createNavigateToUrlPendingIntent(url); remoteViews.setOnClickPendingIntent(R.id.second_beacon_main_layout, pendingIntent); remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.VISIBLE); } else { remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.GONE); } }
From source file:github.daneren2005.dsub.util.Util.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {/*from w w w . j ava 2s . c om*/ int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { rv.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { rv.setTextColor(R.id.notification_artist, colors.getSecond()); } if (!playing) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play); rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop); } // Create actions for media buttons PendingIntent pendingIntent; if (playing) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent); Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(R.id.control_next, pendingIntent); }
From source file:com.andreadec.musicplayer.MusicService.java
private void updateNotificationMessage() { /* Update remote control client */ if (Build.VERSION.SDK_INT >= 14) { if (currentPlayingItem == null) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); } else {//from w ww . jav a2 s . c o m if (isPlaying()) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, currentPlayingItem.getTitle()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, currentPlayingItem.getArtist()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentPlayingItem.getArtist()); metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getDuration()); if (currentPlayingItem.hasImage()) { metadataEditor.putBitmap(METADATA_KEY_ARTWORK, currentPlayingItem.getImage()); } else { metadataEditor.putBitmap(METADATA_KEY_ARTWORK, icon.copy(icon.getConfig(), false)); } metadataEditor.apply(); } } /* Update notification */ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.audio_white); //notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); notificationBuilder.setOngoing(true); int playPauseIcon = isPlaying() ? R.drawable.pause : R.drawable.play; //int playPauseString = isPlaying() ? R.string.pause : R.string.play; notificationBuilder.setContentIntent(pendingIntent); String notificationMessage = ""; if (currentPlayingItem == null) { notificationMessage = getResources().getString(R.string.noSong); } else { if (currentPlayingItem.getArtist() != null && !currentPlayingItem.getArtist().equals("")) notificationMessage = currentPlayingItem.getArtist() + " - "; notificationMessage += currentPlayingItem.getTitle(); } /*notificationBuilder.addAction(R.drawable.previous, getResources().getString(R.string.previous), previousPendingIntent); notificationBuilder.addAction(playPauseIcon, getResources().getString(playPauseString), playpausePendingIntent); notificationBuilder.addAction(R.drawable.next, getResources().getString(R.string.next), nextPendingIntent);*/ notificationBuilder.setContentTitle(getResources().getString(R.string.app_name)); notificationBuilder.setContentText(notificationMessage); notification = notificationBuilder.build(); RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.layout_notification); if (currentPlayingItem == null) { notificationLayout.setTextViewText(R.id.textViewArtist, getString(R.string.app_name)); notificationLayout.setTextViewText(R.id.textViewTitle, getString(R.string.noSong)); notificationLayout.setImageViewBitmap(R.id.imageViewNotification, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } else { notificationLayout.setTextViewText(R.id.textViewArtist, currentPlayingItem.getArtist()); notificationLayout.setTextViewText(R.id.textViewTitle, currentPlayingItem.getTitle()); Bitmap image = currentPlayingItem.getImage(); if (image != null) { notificationLayout.setImageViewBitmap(R.id.imageViewNotification, image); } else { notificationLayout.setImageViewBitmap(R.id.imageViewNotification, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } } notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationQuit, quitPendingIntent); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPrevious, previousPendingIntent); notificationLayout.setImageViewResource(R.id.buttonNotificationPlayPause, playPauseIcon); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPlayPause, playpausePendingIntent); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationNext, nextPendingIntent); notification.bigContentView = notificationLayout; notificationManager.notify(Constants.NOTIFICATION_MAIN, notification); }
From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) { String title = dataInfo.getTitle(); String body = dataInfo.getAlert(); String message = dataInfo.getPushDataString(); Builder builder = new Builder(context); builder.setAutoCancel(true);/* ww w . jav a2 s .c om*/ builder.setContentTitle(title); // builder.setContentText(body); // builder.setTicker(body); // ?? String[] remindType = dataInfo.getRemindType(); if (remindType != null) { if (remindType.length == 3) { builder.setDefaults(Notification.DEFAULT_ALL); } else { int defaults = 0; for (int i = 0; i < remindType.length; i++) { if ("sound".equalsIgnoreCase(remindType[i])) { defaults = Notification.DEFAULT_SOUND; continue; } if ("shake".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_VIBRATE; continue; } if ("breathe".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_LIGHTS; continue; } } builder.setDefaults(defaults); } } Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); builder.setSmallIcon(icon); builder.setWhen(System.currentTimeMillis()); // String iconUrl = dataInfo.getIconUrl(); boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl); Bitmap bitmap = null; if (!isDefaultIcon) { bitmap = getIconBitmap(context, iconUrl); } String fontColor = dataInfo.getFontColor(); RemoteViews remoteViews = null; if (!TextUtils.isEmpty(fontColor)) { int color = BUtility.parseColor(fontColor); int alphaColor = parseAlphaColor(fontColor); remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view")); // Title remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title); remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color); // Body remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body); remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor); // LargeIcon if (bitmap != null) { remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap); } else { remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"), EUExUtil.getResDrawableID("icon")); } // Time SimpleDateFormat format = new SimpleDateFormat("HH:mm"); remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"), format.format(System.currentTimeMillis())); remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor); builder.setContent(remoteViews); } Intent notiIntent = new Intent(context, EBrowserActivity.class); notiIntent.putExtra("ntype", F_TYPE_PUSH); notiIntent.putExtra("data", body); notiIntent.putExtra("message", message); Bundle bundle = new Bundle(); bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo); notiIntent.putExtras(bundle); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = builder.build(); // Android v4bug2.3?Builder?NotificationRemoteView?? if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) { notification.contentView = remoteViews; } manager.notify(notificationNB, notification); notificationNB++; }
From source file:io.teak.sdk.NotificationBuilder.java
public static Notification createNativeNotification(final Context context, Bundle bundle, TeakNotification teakNotificaton) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Rich text message Spanned richMessageText = Html.fromHtml(teakNotificaton.message); // Configure notification behavior builder.setPriority(NotificationCompat.PRIORITY_MAX); builder.setDefaults(NotificationCompat.DEFAULT_ALL); builder.setOnlyAlertOnce(true);// w w w . j av a 2 s . co m builder.setAutoCancel(true); builder.setTicker(richMessageText); // Set small view image try { PackageManager pm = context.getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); builder.setSmallIcon(ai.icon); } catch (Exception e) { Log.e(LOG_TAG, "Unable to load icon resource for Notification."); return null; } Random rng = new Random(); // Create intent to fire if/when notification is cleared Intent pushClearedIntent = new Intent( context.getPackageName() + TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX); pushClearedIntent.putExtras(bundle); PendingIntent pushClearedPendingIntent = PendingIntent.getBroadcast(context, rng.nextInt(), pushClearedIntent, PendingIntent.FLAG_ONE_SHOT); builder.setDeleteIntent(pushClearedPendingIntent); // Create intent to fire if/when notification is opened, attach bundle info Intent pushOpenedIntent = new Intent( context.getPackageName() + TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX); pushOpenedIntent.putExtras(bundle); PendingIntent pushOpenedPendingIntent = PendingIntent.getBroadcast(context, rng.nextInt(), pushOpenedIntent, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(pushOpenedPendingIntent); // Because we can't be certain that the R class will line up with what is at SDK build time // like in the case of Unity et. al. class IdHelper { public int id(String identifier) { int ret = context.getResources().getIdentifier(identifier, "id", context.getPackageName()); if (ret == 0) { throw new Resources.NotFoundException("Could not find R.id." + identifier); } return ret; } public int layout(String identifier) { int ret = context.getResources().getIdentifier(identifier, "layout", context.getPackageName()); if (ret == 0) { throw new Resources.NotFoundException("Could not find R.layout." + identifier); } return ret; } } IdHelper R = new IdHelper(); // Declaring local as 'R' ensures we don't accidentally use the other R // Configure notification small view RemoteViews smallView = new RemoteViews(context.getPackageName(), Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? R.layout("teak_notif_no_title_v21") : R.layout("teak_notif_no_title")); // Set small view image try { PackageManager pm = context.getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); smallView.setImageViewResource(R.id("left_image"), ai.icon); builder.setSmallIcon(ai.icon); } catch (Exception e) { Log.e(LOG_TAG, "Unable to load icon resource for Notification."); return null; } // Set small view text smallView.setTextViewText(R.id("text"), richMessageText); // Check for Jellybean (API 16, 4.1)+ for expanded view RemoteViews bigView = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && teakNotificaton.longText != null && !teakNotificaton.longText.isEmpty()) { bigView = new RemoteViews(context.getPackageName(), Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? R.layout("teak_big_notif_image_text_v21") : R.layout("teak_big_notif_image_text")); // Set big view text bigView.setTextViewText(R.id("text"), Html.fromHtml(teakNotificaton.longText)); URI imageAssetA = null; try { imageAssetA = new URI(teakNotificaton.imageAssetA); } catch (Exception ignored) { } Bitmap topImageBitmap = null; if (imageAssetA != null) { try { URL aURL = new URL(imageAssetA.toString()); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); topImageBitmap = BitmapFactory.decodeStream(bis); bis.close(); is.close(); } catch (Exception ignored) { } } if (topImageBitmap == null) { try { InputStream istr = context.getAssets().open("teak_notif_large_image_default.png"); topImageBitmap = BitmapFactory.decodeStream(istr); } catch (Exception ignored) { } } if (topImageBitmap != null) { // Set large bitmap bigView.setImageViewBitmap(R.id("top_image"), topImageBitmap); } else { Log.e(LOG_TAG, "Unable to load image asset for Notification."); // Hide pulldown smallView.setViewVisibility(R.id("pulldown_layout"), View.INVISIBLE); } } else { // Hide pulldown smallView.setViewVisibility(R.id("pulldown_layout"), View.INVISIBLE); } // Voodoo from http://stackoverflow.com/questions/28169474/notification-background-in-android-lollipop-is-white-can-we-change-it int topId = Resources.getSystem().getIdentifier("status_bar_latest_event_content", "id", "android"); int topBigLayout = Resources.getSystem().getIdentifier("notification_template_material_big_media_narrow", "layout", "android"); int topSmallLayout = Resources.getSystem().getIdentifier("notification_template_material_media", "layout", "android"); RemoteViews topBigView = null; if (bigView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // This is invisible inner view - to have media_actions in hierarchy RemoteViews innerTopView = new RemoteViews("android", topBigLayout); bigView.addView(android.R.id.empty, innerTopView); // This should be on top - we need status_bar_latest_event_content as top layout topBigView = new RemoteViews("android", topBigLayout); topBigView.removeAllViews(topId); topBigView.addView(topId, bigView); } else if (bigView != null) { topBigView = bigView; } // This should be on top - we need status_bar_latest_event_content as top layout RemoteViews topSmallView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { topSmallView = new RemoteViews("android", topSmallLayout); topSmallView.removeAllViews(topId); topSmallView.addView(topId, smallView); } else { topSmallView = smallView; } builder.setContent(topSmallView); Notification n = builder.build(); if (topBigView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // Use reflection to avoid compile-time issues, we check minimum API version above try { Field bigContentViewField = n.getClass().getField("bigContentView"); bigContentViewField.set(n, topBigView); } catch (Exception ignored) { } } return n; }
From source file:com.perm.DoomPlay.PlayingService.java
private RemoteViews getNotifViews(int layoutId) { RemoteViews views = new RemoteViews(getPackageName(), layoutId); Audio audio = audios.get(indexCurrentTrack); views.setTextViewText(R.id.notifTitle, audio.getTitle()); views.setTextViewText(R.id.notifArtist, audio.getArtist()); Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this); if (cover == null) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle();/*from ww w. j av a 2 s .co m*/ } else { //TODO: java.lang.IllegalArgumentException: RemoteViews for widget update exceeds // maximum bitmap memory usage (used: 3240000, max: 2304000) // The total memory cannot exceed that required to fill the device's screen once try { views.setImageViewBitmap(R.id.notifAlbum, cover); } catch (IllegalArgumentException e) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle(); } finally { cover.recycle(); } } views.setImageViewResource(R.id.notifPlay, isPlaying ? R.drawable.widget_pause : R.drawable.widget_play); ComponentName componentName = new ComponentName(this, PlayingService.class); Intent intentPlay = new Intent(actionPlay); intentPlay.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPlay, PendingIntent.getService(this, 0, intentPlay, 0)); Intent intentNext = new Intent(actionNext); intentNext.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifNext, PendingIntent.getService(this, 0, intentNext, 0)); Intent intentPrevious = new Intent(actionPrevious); intentPrevious.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPrevious, PendingIntent.getService(this, 0, intentPrevious, 0)); Intent intentClose = new Intent(actionClose); intentClose.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(this, 0, intentClose, 0)); return views; }
From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java
/** * Prparer le widget avec les lments fixes (nom, ligne, sens...) *///w w w . j a v a 2 s .com protected void prepareWidgetViewInit(final Context context, final RemoteViews views, final Favori favori) { views.setTextViewText(R.id.itemSymbole, favori.getLettre()); // Uniquement pour 2.2 et sup if (Build.VERSION.SDK_INT > 7) { views.setTextColor(R.id.itemSymbole, favori.getCouleurTexte()); views.setTextColor(R.id.itemTitle, favori.getCouleurTexte()); views.setTextColor(R.id.itemDescription, favori.getCouleurTexte()); final GradientDrawable gradientDrawable = ColorUtils.getGradiant(favori.getCouleurBackground()); final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); gradientDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); gradientDrawable.draw(canvas); views.setImageViewBitmap(R.id.widgetHeaderBackground, bitmap); } if (favori.getNomFavori() == null) { views.setTextViewText(R.id.itemTitle, favori.getNomArret()); views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomSens())); } else { views.setTextViewText(R.id.itemTitle, favori.getNomArret()); views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomArret(), favori.getNomSens())); } views.setViewVisibility(R.id.widgetLoading, View.GONE); }
From source file:org.videolan.vlc.AudioService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {//from w ww .j av a 2 s .c o m Bitmap cover = AudioUtil.getCover(this, mCurrentMedia, 64); String title = mCurrentMedia.getTitle(); String artist = mCurrentMedia.getArtist(); String album = mCurrentMedia.getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); Intent notificationIntent = new Intent(this, AudioPlayerActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Util.isJellyBeanOrLater()) { Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iStop = new Intent(ACTION_REMOTE_STOP); PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); if (cover != null) view.setImageViewBitmap(R.id.cover, cover); view.setTextViewText(R.id.songName, title); view.setTextViewText(R.id.artist, artist); view.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view.setOnClickPendingIntent(R.id.play_pause, piPlay); view.setOnClickPendingIntent(R.id.forward, piForward); view.setOnClickPendingIntent(R.id.stop, piStop); view.setOnClickPendingIntent(R.id.content, pendingIntent); RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); if (cover != null) view_expanded.setImageViewBitmap(R.id.cover, cover); view_expanded.setTextViewText(R.id.songName, title); view_expanded.setTextViewText(R.id.artist, artist); view_expanded.setTextViewText(R.id.album, album); view_expanded.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view_expanded.setOnClickPendingIntent(R.id.backward, piBackward); view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay); view_expanded.setOnClickPendingIntent(R.id.forward, piForward); view_expanded.setOnClickPendingIntent(R.id.stop, piStop); view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent); notification = builder.build(); notification.contentView = view; notification.bigContentView = view_expanded; } else { builder.setLargeIcon(cover).setContentTitle(title) .setContentText(Util.isJellyBeanOrLater() ? artist : mCurrentMedia.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startForeground(3, notification); } catch (NoSuchMethodError e) { // Compat library is wrong on 3.2 // http://code.google.com/p/android/issues/detail?id=36359 // http://code.google.com/p/android/issues/detail?id=36502 } }
From source file:com.freeme.filemanager.FileExplorerTabActivity.java
public void showButtonNotify() { mBuilder = new Builder(this); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_button); if (IsFreemeOs.isFreemeOs()) { Bitmap bitMap = getApplicationContext().getPackageManager().getIconBitmapWithThemeBg( getResources().getDrawable(R.drawable.notification_clean), getApplicationContext().getPackageName(), 0); remoteViews.setImageViewBitmap(R.id.filemanager_notification_clean, bitMap); } else {/* w ww . ja v a2s . c o m*/ remoteViews.setImageViewResource(R.id.filemanager_notification_clean, R.drawable.notification_clean); } remoteViews.setTextViewText(R.id.tv_custom_title, getString(R.string.fileManager)); remoteViews.setTextViewText(R.id.tv_custom_text, getString(R.string.clean_text)); Intent buttonIntent = new Intent(ACTION_BUTTON); buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_CLEAN_ID); PendingIntent intent_clean = PendingIntent.getBroadcast(this, 1, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.btn_custom, intent_clean); mBuilder.setContent(remoteViews).setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL)) .setWhen(System.currentTimeMillis()).setPriority(Notification.PRIORITY_DEFAULT).setOngoing(true) .setSmallIcon(R.drawable.notification_small_clean); notify = mBuilder.build(); notify.flags = Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(200, notify); }
From source file:org.videolan.vlc.MediaService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {/*from w ww. j av a 2 s . c o m*/ Bitmap cover = AudioUtil.getCover(this, mCurrentMedia, 64); String title = mCurrentMedia.getTitle(); String artist = mCurrentMedia.getArtist(); String album = mCurrentMedia.getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); Intent notificationIntent = new Intent(this, mIsVout ? MediaPlayerActivity.class : AudioPlayerActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Util.isJellyBeanOrLater()) { Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iStop = new Intent(ACTION_REMOTE_STOP); PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); if (cover != null) view.setImageViewBitmap(R.id.cover, cover); view.setTextViewText(R.id.songName, title); view.setTextViewText(R.id.artist, artist); view.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view.setOnClickPendingIntent(R.id.play_pause, piPlay); view.setOnClickPendingIntent(R.id.forward, piForward); view.setOnClickPendingIntent(R.id.stop, piStop); view.setOnClickPendingIntent(R.id.content, pendingIntent); RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); if (cover != null) view_expanded.setImageViewBitmap(R.id.cover, cover); view_expanded.setTextViewText(R.id.songName, title); view_expanded.setTextViewText(R.id.artist, artist); view_expanded.setTextViewText(R.id.album, album); view_expanded.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view_expanded.setOnClickPendingIntent(R.id.backward, piBackward); view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay); view_expanded.setOnClickPendingIntent(R.id.forward, piForward); view_expanded.setOnClickPendingIntent(R.id.stop, piStop); view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent); notification = builder.build(); notification.contentView = view; notification.bigContentView = view_expanded; } else { builder.setLargeIcon(cover).setContentTitle(title) .setContentText(Util.isJellyBeanOrLater() ? artist : mCurrentMedia.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startForeground(3, notification); } catch (NoSuchMethodError e) { // Compat library is wrong on 3.2 // http://code.google.com/p/android/issues/detail?id=36359 // http://code.google.com/p/android/issues/detail?id=36502 } }