Привет друзья! Мои push-уведомления не работают на Android 5.0 Lollipop. Я проверил этот код на 6.0. Работает нормально, но не работает на устройстве 5.0. Huawei. шаг, который я сделал почти весь шаг, я начинающий
Bitmap largeImage = BitmapFactory.decodeResource(getResources(),R.drawable.musicicon);
//Intent pauseIntent = new Intent("music.playerforandroid.ACTION_PAUSE_MUSIC");
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.ACTION_PAUSE_MUSIC"), 0);
PendingIntent playPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.ACTION_PLAY_MUSIC"), 0);
PendingIntent nextPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.NEXT_PLAY_MUSIC"), 0);
PendingIntent perviousPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.PERVIOUS_PLAY_MUSIC"), 0);
Notification channel = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID_1)
.setSmallIcon(R.drawable.ic_music)
.setContentTitle(song.getTitle())
.setContentText(song.getArtist())
.setLargeIcon(largeImage)
.addAction(R.drawable.ic_prev, "prev", perviousPendingIntent)
.addAction(R.drawable.ic_play, "play", playPendingIntent)
.addAction(R.drawable.ic_stat_name, "pause", pausePendingIntent)
.addAction(R.drawable.ic_next, "next", nextPendingIntent)
.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle().
setShowActionsInCompactView(1, 2, 3))
.build();
mNotificationManagerCompat.notify(1, channel);
package music.playerforandroid;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
public class App extends Application {
public static final String CHANNEL_ID_1 = "channel1";
public static final String CHANNEL_NAME_1 = "FIRSTCHANNEL";
@Override
public void onCreate() {
super.onCreate();
createNotificationChannel();
}
private void createNotificationChannel() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channle1 = new NotificationChannel(
CHANNEL_ID_1,
CHANNEL_NAME_1,
NotificationManager.IMPORTANCE_HIGH
);
channle1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channle1.enableLights(true);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channle1);
}
}
}
и я получаю эту ошибку
E / MediaPlayer: должен быть уже установлен контроллер субтитров
E / MediaPlayer: должен быть уже установлен контроллер субтитров
E / AndroidRuntime: ФАТАЛЬНОЕ ИСКЛЮЧЕНИЕ: главная
Процесс: music.playerforandroid, PID: 22269
android.app.RemoteServiceException: Плохое уведомление, отправленное из пакета music.playerforandroid: Не удалось развернуть RemoteViews для: StatusBarNotification (pkg = music.playerforandroid user = UserHandle {0} id = 1 tag = нулевой счет = 0 key = 0 | music. playerforandroid | 1 | null | 10112: Уведомление (pri = 0 contentView = music.playerforandroid / 0x109007f vibrate = нулевой звук = нулевые значения по умолчанию = 0x0 flags = 0x0 color = 0x00000000 категория = транспортные действия = 4 vis = PRIVATE))
на android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1534)
на android.os.Handler.dispatchMessage (Handler.java:102)
на android.os.Looper.loop (Looper.java:135)
на android.app.ActivityThread.main (ActivityThread.java:5538)
в java.lang.reflect.Method.invoke (родной метод)
в java.lang.reflect.Method.invoke (Method.java:372)
на com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:960)
на com.android.internal.os.ZygoteInit.main (ZygoteInit.java:755)