Я создаю музыкальное приложение, при воспроизведении любой песни, чтобы приложение показывало в Notification Player изображение, имя исполнителя и название песни (для этого я использую эффект выделения).На большинстве устройств ОС 4/5/6/7 в порядке, песня Title может работать с эффектом выделения, кроме ОС 8. Что не так?И что мне делать?
Этоtification_player.ics.xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/notify_image_jacket"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/notify_image_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/image_description"
android:src="@drawable/ic_notify_play" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="24dp"
android:layout_weight="1"
android:orientation="horizontal" >
<!-- #1242 - Add title color white-->
<TextView
android:id="@+id/notify_text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/font_color_white"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true">
<requestFocus android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true"/>
</TextView>
<TextView
android:id="@+id/notify_text_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/separator"
android:textColor="@color/font_color_white" />
<!-- #1242 - Add title color white-->
<TextView
android:id="@+id/notify_text_artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@color/font_color_white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Я использую RemoteViews и канал уведомлений
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
views = new RemoteViews(getPackageName(), R.layout.notification_player_ics);
}
views.setTextViewText(R.id.notify_text_title, LibraryUtility.getDispTrackName(mContext, title));
views.setTextViewText(R.id.notify_text_artist, LibraryUtility.getDispArtistName(mContext, artist));
/**#2178 - Edit - Issue for media notifications to support Android Oreo - start */
String channelid = String.valueOf(NotificationConst.NOTIFICATION_MEDIASERVICE);
int pFlag = PendingIntent.FLAG_UPDATE_CURRENT;
//PLUS_MUSE-1194 【SCL23】通知エリアを押下した時にアプリが復帰しない対応
if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
//4.4の一部端末でFLAG_UPDATE_CURRENTが使用できないためFLAG_CANCEL_CURRENTで代用
pFlag = PendingIntent.FLAG_CANCEL_CURRENT;
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, pFlag);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getResources().getString(R.string.app_name);
Utility.createChannelNotifications(mNotificationManager, NotificationManager.IMPORTANCE_LOW, name, channelid);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
if (mNotification == null) {
mNotification = new Notification();
}
mNotification.contentView = views;
mNotification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
mNotification.icon = R.drawable.ic_notify_play;
mNotification.contentIntent = pendingIntent;
} else {
if (mBuilder == null) {
mBuilder = new NotificationCompat.Builder(getApplicationContext(), channelid);
}
mBuilder.setSmallIcon(R.drawable.ic_notify_play);
mBuilder.setCustomContentView(views);
//mBuilder.setContent(views);
mBuilder.setAutoCancel(false);
mBuilder.setOngoing(true);
mBuilder.setColor(ContextCompat.getColor(mContext, R.color.bg_color_black));
mBuilder.setContentIntent(pendingIntent);
}
Это createChannelNotifications () метод:
public static void createChannelNotifications(NotificationManager notificationManager, int importance, CharSequence name, String channelid) {
String id = channelid;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mChannel.setLightColor(Color.GREEN);
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
mChannel.setVibrationPattern(new long[]{0});
if (notificationManager != null) {
notificationManager.createNotificationChannel(mChannel);
}
}