List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:android.app.Notification.java
/** * Sets the {@link #contentView} field to be a view with the standard "Latest Event" * layout.//from w w w . java 2 s . c o m * * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields * in the view.</p> * @param context The context for your application / activity. * @param contentTitle The title that goes in the expanded entry. * @param contentText The text that goes in the expanded entry. * @param contentIntent The intent to launch when the user clicks the expanded notification. * If this is an activity, it must include the * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires * that you take care of task management as described in the * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back * Stack</a> document. * * @deprecated Use {@link Builder} instead. */ @Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { // TODO: rewrite this to use Builder RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_template_base); if (this.icon != 0) { contentView.setImageViewResource(R.id.icon, this.icon); } if (priority < PRIORITY_LOW) { contentView.setInt(R.id.icon, "setBackgroundResource", R.drawable.notification_template_icon_low_bg); contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", R.drawable.notification_bg_low); } if (contentTitle != null) { contentView.setTextViewText(R.id.title, contentTitle); } if (contentText != null) { contentView.setTextViewText(R.id.text, contentText); } if (this.when != 0) { contentView.setViewVisibility(R.id.time, View.VISIBLE); contentView.setLong(R.id.time, "setTime", when); } if (this.number != 0) { NumberFormat f = NumberFormat.getIntegerInstance(); contentView.setTextViewText(R.id.info, f.format(this.number)); } this.contentView = contentView; this.contentIntent = contentIntent; }
From source file:cw.kop.autobackground.LiveWallpaperService.java
@SuppressLint("NewApi") private void startNotification(boolean useNotification) { if (useNotification) { normalView = new RemoteViews(getPackageName(), R.layout.notification_layout); normalView.setInt(R.id.notification_container, "setBackgroundColor", AppSettings.getNotificationColor()); normalView.setImageViewResource(R.id.notification_icon, R.drawable.app_icon); normalView.setTextViewText(R.id.notification_title, AppSettings.getNotificationTitle()); normalView.setInt(R.id.notification_title, "setTextColor", AppSettings.getNotificationTitleColor()); normalView.setTextViewText(R.id.notification_summary, AppSettings.getNotificationSummary()); normalView.setInt(R.id.notification_summary, "setTextColor", AppSettings.getNotificationSummaryColor()); Drawable coloredImageOne = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(0)); Drawable coloredImageTwo = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(1)); Drawable coloredImageThree = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(2)); coloredImageOne.mutate().setColorFilter(AppSettings.getNotificationOptionColor(0), PorterDuff.Mode.MULTIPLY); coloredImageTwo.mutate().setColorFilter(AppSettings.getNotificationOptionColor(1), PorterDuff.Mode.MULTIPLY); coloredImageThree.mutate().setColorFilter(AppSettings.getNotificationOptionColor(2), PorterDuff.Mode.MULTIPLY); Bitmap mutableBitmapOne = Bitmap.createBitmap(coloredImageOne.getIntrinsicWidth(), coloredImageOne.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasOne = new Canvas(mutableBitmapOne); coloredImageOne.setBounds(0, 0, coloredImageOne.getIntrinsicWidth(), coloredImageOne.getIntrinsicHeight()); coloredImageOne.draw(canvasOne); Bitmap mutableBitmapTwo = Bitmap.createBitmap(coloredImageTwo.getIntrinsicWidth(), coloredImageTwo.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasTwo = new Canvas(mutableBitmapTwo); coloredImageTwo.setBounds(0, 0, coloredImageTwo.getIntrinsicWidth(), coloredImageTwo.getIntrinsicHeight()); coloredImageTwo.draw(canvasTwo); Bitmap mutableBitmapThree = Bitmap.createBitmap(coloredImageThree.getIntrinsicWidth(), coloredImageThree.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasThree = new Canvas(mutableBitmapThree); coloredImageThree.setBounds(0, 0, coloredImageThree.getIntrinsicWidth(), coloredImageThree.getIntrinsicHeight()); coloredImageThree.draw(canvasThree); if (AppSettings.useNotificationGame()) { if (setupGameTiles()) { bigView = new RemoteViews(getPackageName(), R.layout.notification_game); tileIds = new int[] { R.id.notification_game_tile_0, R.id.notification_game_tile_1, R.id.notification_game_tile_2, R.id.notification_game_tile_3, R.id.notification_game_tile_4, R.id.notification_game_tile_5, R.id.notification_game_tile_6, R.id.notification_game_tile_7, R.id.notification_game_tile_8, R.id.notification_game_tile_9 }; bigView.setOnClickPendingIntent(tileIds[0], pendingTile0); bigView.setOnClickPendingIntent(tileIds[1], pendingTile1); bigView.setOnClickPendingIntent(tileIds[2], pendingTile2); bigView.setOnClickPendingIntent(tileIds[3], pendingTile3); bigView.setOnClickPendingIntent(tileIds[4], pendingTile4); bigView.setOnClickPendingIntent(tileIds[5], pendingTile5); bigView.setOnClickPendingIntent(tileIds[6], pendingTile6); bigView.setOnClickPendingIntent(tileIds[7], pendingTile7); bigView.setOnClickPendingIntent(tileIds[8], pendingTile8); bigView.setOnClickPendingIntent(tileIds[9], pendingTile9); } else { bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout); closeNotificationDrawer(LiveWallpaperService.this); Toast.makeText(LiveWallpaperService.this, "Not enough images to create game", Toast.LENGTH_LONG) .show();//ww w.j a v a2s .c o m AppSettings.setUseNotificationGame(false); } } else { bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout); } bigView.setInt(R.id.notification_big_container, "setBackgroundColor", AppSettings.getNotificationColor()); bigView.setImageViewResource(R.id.notification_big_icon, R.drawable.app_icon); bigView.setTextViewText(R.id.notification_big_title, AppSettings.getNotificationTitle()); bigView.setInt(R.id.notification_big_title, "setTextColor", AppSettings.getNotificationTitleColor()); bigView.setTextViewText(R.id.notification_big_summary, AppSettings.getNotificationSummary()); bigView.setInt(R.id.notification_big_summary, "setTextColor", AppSettings.getNotificationSummaryColor()); bigView.setImageViewBitmap(R.id.notification_button_one_image, mutableBitmapOne); bigView.setImageViewBitmap(R.id.notification_button_two_image, mutableBitmapTwo); bigView.setImageViewBitmap(R.id.notification_button_three_image, mutableBitmapThree); bigView.setTextViewText(R.id.notification_button_one_text, AppSettings.getNotificationOptionTitle(0)); bigView.setInt(R.id.notification_button_one_text, "setTextColor", AppSettings.getNotificationOptionColor(0)); bigView.setTextViewText(R.id.notification_button_two_text, AppSettings.getNotificationOptionTitle(1)); bigView.setInt(R.id.notification_button_two_text, "setTextColor", AppSettings.getNotificationOptionColor(1)); bigView.setTextViewText(R.id.notification_button_three_text, AppSettings.getNotificationOptionTitle(2)); bigView.setInt(R.id.notification_button_three_text, "setTextColor", AppSettings.getNotificationOptionColor(2)); if (getIntentForNotification(AppSettings.getNotificationIconAction()) != null) { normalView.setOnClickPendingIntent(R.id.notification_icon, getIntentForNotification(AppSettings.getNotificationIconAction())); bigView.setOnClickPendingIntent(R.id.notification_big_icon, getIntentForNotification(AppSettings.getNotificationIconAction())); } else { normalView.setOnClickPendingIntent(R.id.notification_icon, pendingAppIntent); bigView.setOnClickPendingIntent(R.id.notification_big_icon, pendingAppIntent); } notificationBuilder = new Notification.Builder(this).setContent(normalView) .setSmallIcon(R.drawable.notification_icon).setOngoing(true); if (Build.VERSION.SDK_INT >= 16) { if (AppSettings.useNotificationGame()) { notificationBuilder.setPriority(Notification.PRIORITY_MAX); } else { notificationBuilder.setPriority(Notification.PRIORITY_MIN); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(0)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_one, getIntentForNotification(AppSettings.getNotificationOptionTitle(0))); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(1)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_two, getIntentForNotification(AppSettings.getNotificationOptionTitle(1))); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(2)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_three, getIntentForNotification(AppSettings.getNotificationOptionTitle(2))); } } else { notificationBuilder.setContentTitle(AppSettings.getNotificationTitle()); notificationBuilder.setContentText(AppSettings.getNotificationSummary()); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(0), AppSettings.getNotificationOptionTitle(0), getIntentForNotification(AppSettings.getNotificationOptionTitle(0))); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(1), AppSettings.getNotificationOptionTitle(1), getIntentForNotification(AppSettings.getNotificationOptionTitle(1))); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(2), AppSettings.getNotificationOptionTitle(2), getIntentForNotification(AppSettings.getNotificationOptionTitle(2))); } pushNotification(); if (FileHandler.getCurrentBitmapFile() != null) { notifyChangeImage(); } } else { notificationManager.cancel(NOTIFICATION_ID); } }
From source file:com.nd.android.u.square.service.MusicPlaybackService.java
Notification buildNotification(String text) { // Log.d("yulin", "buildNotification, musicName = " + musicName + ", mIsPause = " + mIsPause); NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); mNotificationBuilder.setSmallIcon(R.drawable.ic_square_notification_music_play); mNotificationBuilder.setTicker(text); //Grab the notification layout. RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.square_notification_music_play); Intent stopServiceIntent = new Intent(ACTION_STOP); PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, stopServiceIntent, 0);/*from ww w . ja v a 2s . c o m*/ //Set the notification content. notificationView.setTextViewText(R.id.notification_base_line_one, text); //Set the "Stop Service" pending intent. notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent); //Set the album art. notificationView.setImageViewResource(R.id.notification_base_image, R.drawable.ic_square_music_default); //Attach the shrunken layout to the notification. mNotificationBuilder.setContent(notificationView); //Build the notification object and set its flags. Notification notification = mNotificationBuilder.build(); notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:saphion.services.ForegroundService.java
@SuppressWarnings("deprecation") void handleCommand() { mPref = getSharedPreferences(PREF_NAME, MODE_MULTI_PROCESS); // if (ACTION_FOREGROUND.equals(intent.getAction())) { // In this sample, we'll use the same text for the ticker and the // expanded notification // CharSequence text = getText(R.string.foreground_service_started); // Set the icon, scrolling text and timestamp try {//from w w w . j a v a2s . c o m handleTrigger(level); } catch (Exception ex) { Log.d(ex.toString()); } RemoteViews rvNoti = new RemoteViews(getPackageName(), R.layout.smallnoti); NotificationCompat.Builder builder;/* * = new NotificationCompat.Builder( * getBaseContext * ()).setContent(rvNoti); * builder.build(); */ Notification notification = new Notification(getId(level), null, 0); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = null; Intent localIntent; switch (mPref.getInt(PreferenceHelper.NOTI_ONCLICK, 2)) { case 0: contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TabNavigation.class), 0); break; case 1: localIntent = new Intent(); localIntent.setFlags(346030080); localIntent.setAction("android.intent.action.POWER_USAGE_SUMMARY"); contentIntent = PendingIntent.getActivity(this, 0, localIntent, 0); break; case 2: contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Controller.class), 0); break; case 3: contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ToggleDialog.class), 0); break; } String prevTime = mPref.getString(PreferenceHelper.PREV_BAT_TIME, TimeFuncs.getCurrentTimeStamp()); long diff = TimeFuncs.newDiff(TimeFuncs.GetItemDate(prevTime), TimeFuncs.GetItemDate(TimeFuncs.getCurrentTimeStamp())); Log.d("New diff " + diff); // TODO Log.d("Previous Date: " + TimeFuncs.GetItemDate(prevTime)); Log.d("Current Date: " + TimeFuncs.GetItemDate(TimeFuncs.getCurrentTimeStamp())); // Log.d( "Previous Timestamp " + level + ""); // Log.d( "Current Timestamp " + level + ""); String subtext; Log.d("Current Level " + level + ""); Log.d("Previous Level " + mPref.getInt(PreferenceHelper.PREV_BAT_LEVEL, level) + ""); if (level < mPref.getInt(PreferenceHelper.PREV_BAT_LEVEL, level)) { diff = (long) (mPref.getLong(PreferenceHelper.BAT_DISCHARGE, diff)); reqTime = diff * level; subtext = "Empty in " + TimeFuncs.convtohournminnday(reqTime); // mPref // .edit().putLong(PreferenceHelper.BAT_DISCHARGE, diff) // .commit(); Log.d("Discharging with " + diff); } else { if (level > mPref.getInt(PreferenceHelper.PREV_BAT_LEVEL, level)) { if (level != 100 && TimeFuncs.convtohournminnday(diff * (100 - level)).equalsIgnoreCase("0 Minute(s)")) { reqTime = (long) (81 * (100 - level)); subtext = "Full Charge in " + TimeFuncs.convtohournminnday(reqTime); } else { reqTime = diff * (100 - level); subtext = "Full Charge in " + TimeFuncs.convtohournminnday(reqTime); mPref.edit().putLong(PreferenceHelper.BAT_CHARGE, diff).commit(); } Log.d("Charging with " + diff); } else { if (isconnected) { reqTime = (long) (mPref.getLong(PreferenceHelper.BAT_CHARGE, 81) * (100 - level)); subtext = "Full Charge in " + TimeFuncs.convtohournminnday(reqTime); Log.d("Estimating Charging"); // mPref // .edit().putLong("batcharge", diff).commit(); Log.d("EST Charging with " + diff); } else { reqTime = (long) (mPref.getLong(PreferenceHelper.BAT_DISCHARGE, 792) * (level)); subtext = "Empty in " + TimeFuncs.convtohournminnday(reqTime); Log.d("Estimating Discharging with: " + (long) (mPref.getLong(PreferenceHelper.BAT_DISCHARGE, 792))); } } } if (level == 100 && isconnected) { subtext = "Fully Charged"; reqTime = 0; } String mainText = mPref.getString(PreferenceHelper.LAST_CHARGED, TimeFuncs.getCurrentTimeStamp()); if (isconnected) { if (mPref.getBoolean("plugged?", true)) mPref.edit().putString(PreferenceHelper.LAST_CHARGED, TimeFuncs.getCurrentTimeStamp()).commit(); String time = TimeFuncs.convtohournminnday(TimeFuncs.newDiff(TimeFuncs.GetItemDate(mainText), TimeFuncs.GetItemDate(TimeFuncs.getCurrentTimeStamp()))); if (!time.equals("0 Minute(s)")) mainText = "Plugged " + time + " ago"; else mainText = "Plugged " + "right now"; mPref.edit().putBoolean("plugged?", false).commit(); } else { if (!mPref.getBoolean("plugged?", true)) { mPref.edit().putBoolean("plugged?", true).commit(); mPref.edit().putString(PreferenceHelper.LAST_CHARGED, TimeFuncs.getCurrentTimeStamp()).commit(); } mainText = mPref.getString(PreferenceHelper.LAST_CHARGED, TimeFuncs.getCurrentTimeStamp()); String time = TimeFuncs.convtohournminnday(TimeFuncs.newDiff(TimeFuncs.GetItemDate(mainText), TimeFuncs.GetItemDate(TimeFuncs.getCurrentTimeStamp()))); if (!time.equals("0 Minute(s)")) mainText = "Unplugged " + time + " ago"; else mainText = "Unplugged " + "right now"; } String tempsubtext = subtext; subtext = setNotText(subtext, mainText, mPref.getInt(PreferenceHelper.NOTI_SUBTEXT, 3)); mainText = setNotText(tempsubtext, mainText, mPref.getInt(PreferenceHelper.NOTI_MAINTEXT, 6)); // Set the info for the views that show in the notification panel int srcId = getId(level); builder = new NotificationCompat.Builder(this).setSmallIcon(srcId).setAutoCancel(false).setOngoing(true) .setContentTitle(mainText).setContentText(subtext).setTicker(null).setWhen(0); // modification rvNoti.setImageViewResource(R.id.notification_icon, srcId); rvNoti.setTextViewText(R.id.tvNotiPrevmainText, mainText); rvNoti.setTextViewText(R.id.tvNotiPrevsubText, subtext); rvLargeNoti = new RemoteViews(getPackageName(), R.layout.largenoti); /*if (Build.VERSION.SDK_INT != 20)*/ builder.setContent(rvNoti); // Intent notificationIntent = new Intent(this, // ForegroundService.class); // contentIntent = PendingIntent.getActivity(this, 0, // notificationIntent, // PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); switch (mPref.getInt(PreferenceHelper.NOTI_PRIORITY, 2)) { case 0: builder.setPriority(NotificationCompat.PRIORITY_HIGH); break; case 1: builder.setPriority(NotificationCompat.PRIORITY_MIN); break; case 2: builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); break; case 3: builder.setPriority(NotificationCompat.PRIORITY_LOW); break; case 4: builder.setPriority(NotificationCompat.PRIORITY_MAX); break; } // builder. notification = builder.build(); /*if (Build.VERSION.SDK_INT != 20)*/ notification.contentView = rvNoti; /*if (Build.VERSION.SDK_INT == 20) { * builder = new * Notification.Builder(this).setContentTitle(mainText) * .setContentText(subtext).setTicker(null).setWhen(0) * .setOngoing(true).setSmallIcon(srcId) * .setContentIntent(pendingIntent).addAction(call) * .addAction(cancel).setAutoCancel(false); setKitkatActions(builder); notification = builder.build(); } else*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { rvLargeNoti.setImageViewResource(R.id.notification_icon_large, srcId); if (mPref.getBoolean(PreferenceHelper.SHOW_CHART, true)) { vals = new ArrayList<Double>(); dates = new ArrayList<Double>(); vals = SerialPreference.retPrefs(getBaseContext(), PreferenceHelper.BAT_VALS); dates = SerialPreference.retPrefs(getBaseContext(), PreferenceHelper.BAT_TIME); GraphicalView mChartView = ChartFactory.getTimeChartView(getBaseContext(), getDateDataset(), getRenderer(), "EEE, h:mm a"); Bitmap outBitmap = Bitmap.createScaledBitmap(loadBitmapFromView(mChartView), getResources().getDisplayMetrics().widthPixels, Functions.ReturnHeight(140, getBaseContext()), true); rvLargeNoti.setImageViewBitmap(R.id.ivchart_large, outBitmap); rvLargeNoti.setViewVisibility(R.id.ivchart_large, View.VISIBLE); } else { rvLargeNoti.setViewVisibility(R.id.ivchart_large, View.GONE); } rvLargeNoti.setTextViewText(R.id.tvNotiPrevmainText_large, mainText); rvLargeNoti.setTextViewText(R.id.tvNotiPrevsubText_large, subtext); setResourceImages(rvLargeNoti); setIntents(rvLargeNoti); notification.bigContentView = rvLargeNoti; } if (mPref.getBoolean(PreferenceHelper.NOTIFICATION_ENABLE, true)) { /* * startForegroundCompat(R.string.foreground_service_started, * notification); */ startForeground(notiID, notification); } else { notification.icon = R.drawable.abc_ab_bottom_transparent_dark_holo; try { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) notification.priority = Notification.PRIORITY_MIN; } catch (Exception ex) { } startForeground(notiID, notification); startService(new Intent(ForegroundService.this, FakeService.class)); } /* * if(DISPLAY != null){ if(DISPLAY){ startForeground(notiID, * notification); Log.Toast(getBaseContext(), "displaying notification", * Toast.LENGTH_LONG); }else{ Log.Toast(getBaseContext(), * "not gonna display", Toast.LENGTH_LONG); * //startForegroundCompat(R.string.foreground_service_started, null); * notification.icon = R.drawable.abc_ab_bottom_transparent_dark_holo; * notification.priority = Notification.PRIORITY_MIN; * startForeground(notiID, notification); startService(new * Intent(ForegroundService.this, FakeService.class)); } } */ if (level != mPref.getInt(PreferenceHelper.PREV_BAT_LEVEL, level)) mPref.edit().putString(PreferenceHelper.PREV_BAT_TIME, TimeFuncs.getCurrentTimeStamp()).commit(); mPref.edit().putInt(PreferenceHelper.PREV_BAT_LEVEL, level).commit(); }
From source file:com.irccloud.android.Notifications.java
@SuppressLint("NewApi") private android.app.Notification buildNotification(String ticker, int bid, long[] eids, String title, String text, Spanned big_text, int count, Intent replyIntent, Spanned wear_text, String network, String auto_messages[]) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext()) .setContentTitle(title + ((network != null) ? (" (" + network + ")") : "")) .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker) .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify) .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getColor(R.color.dark_blue)) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(false); if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 10000) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults(android.app.Notification.DEFAULT_VIBRATE); String ringtone = prefs.getString("notify_ringtone", "content://settings/system/notification_sound"); if (ringtone != null && ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); }/*from w w w. j a v a 2 s . com*/ int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1")); if (led_color == 1) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults( android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE); else builder.setDefaults(android.app.Notification.DEFAULT_LIGHTS); } else if (led_color == 2) { builder.setLights(0xFF0000FF, 500, 500); } SharedPreferences.Editor editor = prefs.edit(); editor.putLong("lastNotificationTime", System.currentTimeMillis()); editor.commit(); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getString(R.string.DISMISS_NOTIFICATION)); dismiss.setData(Uri.parse("irccloud-dismiss://" + bid)); dismiss.putExtra("bid", bid); dismiss.putExtra("eids", eids); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast( IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent( PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setDeleteIntent(dismissPendingIntent); if (replyIntent != null) { WearableExtender extender = new WearableExtender(); PendingIntent replyPendingIntent = PendingIntent.getService( IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); extender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()) .build()); if (count > 1 && wear_text != null) extender.addPage( new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext()) .setContentText(wear_text).extend(new WearableExtender().setStartScrollBottom(true)) .build()); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( title + ((network != null) ? (" (" + network + ")") : "")) .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent, new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); if (auto_messages != null) { for (String m : auto_messages) { if (m != null && m.length() > 0) { unreadConvBuilder.addMessage(m); } } } else { unreadConvBuilder.addMessage(text); } unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000); builder.extend(extender) .extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build())); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent); } android.app.Notification notification = builder.build(); RemoteViews contentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification); contentView.setTextViewText(R.id.title, title + " (" + network + ")"); contentView.setTextViewText(R.id.text, (count == 1) ? Html.fromHtml(text) : (count + " unread highlights.")); contentView.setLong(R.id.time, "setTime", eids[0] / 1000); notification.contentView = contentView; if (Build.VERSION.SDK_INT >= 16 && big_text != null) { RemoteViews bigContentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification_expanded); bigContentView.setTextViewText(R.id.title, title + (!title.equals(network) ? (" (" + network + ")") : "")); bigContentView.setTextViewText(R.id.text, big_text); bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000); if (count > 3) { bigContentView.setViewVisibility(R.id.more, View.VISIBLE); bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more"); } else { bigContentView.setViewVisibility(R.id.more, View.GONE); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { bigContentView.setViewVisibility(R.id.actions, View.VISIBLE); bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE); i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent); } notification.bigContentView = bigContentView; } return notification; }
From source file:com.massivcode.androidmusicplayer.services.MusicService.java
private void showNotificationUnderLollipop() { Notification.Builder builder = new Notification.Builder(this); RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification); // ? ? ? /*from ww w. j a va 2 s. co m*/ // ========================================================================================= Intent musicPreviousIntent = new Intent(getApplicationContext(), MusicService.class); musicPreviousIntent.setAction(ACTION_PLAY_PREVIOUS); musicPreviousIntent.putExtra("position", getPositionAtPreviousOrNext(ACTION_PLAY_PREVIOUS)); PendingIntent musicPreviousPendingIntent = PendingIntent.getService(getApplicationContext(), 0, musicPreviousIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_previous_ib, musicPreviousPendingIntent); // ========================================================================================= // ? ? ? // ========================================================================================= Intent musicStopIntent = new Intent(getApplicationContext(), MusicService.class); musicStopIntent.setAction(ACTION_PAUSE); PendingIntent musicStopPendingIntent = PendingIntent.getService(getApplicationContext(), 1, musicStopIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_play_ib, musicStopPendingIntent); // ========================================================================================= // ? ? ? // ========================================================================================= Intent musicNextIntent = new Intent(getApplicationContext(), MusicService.class); musicNextIntent.setAction(ACTION_PLAY_NEXT); musicNextIntent.putExtra("position", getPositionAtPreviousOrNext(ACTION_PLAY_NEXT)); PendingIntent musicNextPendingIntent = PendingIntent.getService(getApplicationContext(), 2, musicNextIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_next_ib, musicNextPendingIntent); // ========================================================================================= // ? ? // ========================================================================================= Intent closeIntent = new Intent(getApplicationContext(), MusicService.class); closeIntent.setAction(ACTION_FINISH); PendingIntent closePendingIntent = PendingIntent.getService(getApplicationContext(), 3, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_close_ib, closePendingIntent); // ========================================================================================= // Notification ? PendingIntent // ========================================================================================= Intent activityStartIntent = new Intent(MainActivity.ACTION_NAME); activityStartIntent.putExtra("restore", getCurrentInfo()); PendingIntent activityStartPendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, activityStartIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(activityStartPendingIntent); // ========================================================================================= Bitmap bitmap = null; if (mCurrentMusicInfo != null) { if (mCurrentMusicInfo.getUri() != null) { bitmap = MusicInfoLoadUtil.getBitmap(getApplicationContext(), mCurrentMusicInfo.getUri(), 4); } } if (bitmap == null) { bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_no_image); } remoteViews.setImageViewBitmap(R.id.noti_album_art_iv, bitmap); if (mCurrentMusicInfo != null) { remoteViews.setTextViewText(R.id.noti_artist_tv, mCurrentMusicInfo.getArtist()); remoteViews.setTextViewText(R.id.noti_title_tv, mCurrentMusicInfo.getTitle()); } builder.setContent(remoteViews); builder.setLargeIcon(bitmap); builder.setSmallIcon(R.mipmap.ic_no_image); if (mMediaPlayer.isPlaying()) { remoteViews.setImageViewResource(R.id.noti_play_ib, android.R.drawable.ic_media_pause); } else { remoteViews.setImageViewResource(R.id.noti_play_ib, android.R.drawable.ic_media_play); } builder.setAutoCancel(false); Notification notification = builder.build(); startForeground(1, notification); }
From source file:org.videolan.vlc.audio.AudioService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {/*ww w .ja v a2s . co m*/ Media media = getCurrentMedia(); if (media == null) return; Bitmap cover = AudioUtil.getCover(this, media, 64); String title = media.getTitle(); String artist = media.getArtist(); String album = media.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, MainActivity.class); notificationIntent.setAction(MainActivity.ACTION_SHOW_PLAYER); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (LibVlcUtil.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_w : R.drawable.ic_play_w); 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_w : R.drawable.ic_play_w); 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(LibVlcUtil.isJellyBeanOrLater() ? artist : media.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startService(new Intent(this, AudioService.class)); 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.dzt.musicplay.player.AudioService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { Constant.print_i("AudioService----------->showNotification"); try {/*from w ww . j a va2 s .c om*/ Media media = getCurrentMedia(); if (media == null) return; Bitmap cover = AudioUtil.getCover(this, media, 64); String title = media.getTitle(); String artist = media.getArtist(); String album = media.getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_music).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); //Activity Intent notificationIntent = new Intent(this, MusicPlayActivity.class); notificationIntent.setAction(MusicPlayActivity.ACTION_SHOW_PLAYER); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (LibVlcUtil.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_w : R.drawable.ic_play_w); 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_w : R.drawable.ic_play_w); 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(LibVlcUtil.isJellyBeanOrLater() ? artist : media.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startService(new Intent(this, AudioService.class)); 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 } Constant.print_i("AudioService----------->showNotification----end"); }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * Builds and returns a fully constructed Notification for devices * on Jelly Bean and above (API 16+).// w w w . j a va2 s. c o m */ @SuppressLint("NewApi") private Notification buildJBNotification(SongHelper songHelper) { mNotificationBuilder = new NotificationCompat.Builder(mContext); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); mNotificationBuilder.setSmallIcon(R.mipmap.ic_launcher); //Open up the player screen when the user taps on the notification. Intent launchNowPlayingIntent = new Intent(); launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION); PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, launchNowPlayingIntent, 0); mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent); //Grab the notification layouts. RemoteViews notificationView = new RemoteViews(mContext.getPackageName(), R.layout.notification_custom_layout); RemoteViews expNotificationView = new RemoteViews(mContext.getPackageName(), R.layout.notification_custom_expanded_layout); //Initialize the notification layout buttons. Intent previousTrackIntent = new Intent(); previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION); PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, previousTrackIntent, 0); Intent playPauseTrackIntent = new Intent(); playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION); PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, playPauseTrackIntent, 0); Intent nextTrackIntent = new Intent(); nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION); PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, nextTrackIntent, 0); Intent stopServiceIntent = new Intent(); stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE); PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, stopServiceIntent, 0); //Check if audio is playing and set the appropriate play/pause button. if (mApp.getService().isPlayingMusic()) { notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.ic_play); expNotificationView.setImageViewResource(R.id.notification_expanded_base_play, R.drawable.ic_play); } else { notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.ic_play); expNotificationView.setImageViewResource(R.id.notification_expanded_base_play, R.drawable.ic_play); } //Set the notification content. expNotificationView.setTextViewText(R.id.notification_expanded_base_line_one, songHelper.getTitle()); expNotificationView.setTextViewText(R.id.notification_expanded_base_line_two, songHelper.getArtist()); expNotificationView.setTextViewText(R.id.notification_expanded_base_line_three, songHelper.getAlbum()); notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle()); notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist()); //Set the states of the next/previous buttons and their pending intents. if (mApp.getService().isOnlySongInQueue()) { //This is the only song in the queue, so disable the previous/next buttons. expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE); notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); } else if (mApp.getService().isFirstSongInQueue()) { //This is the the first song in the queue, so disable the previous button. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); } else if (mApp.getService().isLastSongInQueue()) { //This is the last song in the cursor, so disable the next button. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); } else { //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_previous, previousTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent); } //Set the "Stop Service" pending intents. expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_collapse, stopServicePendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent); //Set the album art. expNotificationView.setImageViewBitmap(R.id.notification_expanded_base_image, songHelper.getAlbumArt()); notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt()); //Attach the shrunken layout to the notification. mNotificationBuilder.setContent(notificationView); //Build the notification object. Notification notification = mNotificationBuilder.build(); //Attach the expanded layout to the notification and set its flags. notification.bigContentView = expNotificationView; notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; return notification; }