Как сделать уведомление с поддержкой старых версий андроид (api 16, 17 ..). У меня в тестовом сервисе есть метод, который строит уведомление на поздних версиях андроид все работает (андроид 5,6,7), а на андроид 4.4 и ниже появляется ошибка какая-то. Не ругайте строго я новичок
Метод для создания уведомления
private void showNotify() {
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction(MyConstants.ACTION.MAIN_ACTION);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Intent closeIntent = new Intent(this, MyService.class);
closeIntent.setAction(MyConstants.ACTION.STOP_ACTION);
PendingIntent pCloseIntent = PendingIntent.getService(this, 0, closeIntent, 0);
notification = new NotificationCompat.Builder(this)
.setContentTitle("Тестовый заголовок")
.setContentText("Описание")
.setSmallIcon(R.mipmap.ic_launcher)
.addAction(R.drawable.ic_close, "Закрыть", pCloseIntent)
.setContentIntent(pendingIntent).build();
startForeground(MyConstants.NOTIFICATION_ID.PLAYER_SERVICE_ID, notification);
}
Ошибка
FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification posted from package androidapp.testapp: Couldn't expand RemoteViews for: StatusBarNotification(pkg=androidapp.testapp id=101 tag=null score=0 notn=Notification(pri=0 contentView=androidapp.testapp/0x109008f vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null] 1 action) user=UserHandle{0})
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)