libpd/pd-for-android

PdService crashes when started in foreground on Android Oreo

wyrk opened this issue · 0 comments

wyrk commented

The crash occured on a Pixel 2 with Android 8.1.0 .

The crash occurs with compileSdkVersion = 27 (not sure about previous versions however it didn't happen with 25 on Pixel 2)

Oreo notifications require a channel in order to work.
PdService will crash if started without it.
Adding a channelId to the foreground notification will not affect it.

Something like this should be added in PdService:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager notificationManager =
(NotificationManager) App.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = NOTIFICATION_CHANNEL_ID;
CharSequence channelName = App.getContext().getString(R.string.app_name);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.WHITE);
notificationChannel.enableVibration(true);
if (notificationManager != null)
notificationManager.createNotificationChannel(notificationChannel);
}

example log from crashlytics:
Fatal Exception: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x42 color=0x00000000 vis=PRIVATE)