How to make a notification with support for older versions of android (api 16, 17 ..). In my test service, there is a method that builds a notification on later versions of android, everything works (android 5,6,7), and on android 4.4 and below some kind of error appears. Do not scold me strictly new
Method to create a notification
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); } Mistake
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)