diff --git a/app/src/main/java/com/openvehicles/OVMS/api/ApiService.kt b/app/src/main/java/com/openvehicles/OVMS/api/ApiService.kt index ded45b6d..c8cc4991 100644 --- a/app/src/main/java/com/openvehicles/OVMS/api/ApiService.kt +++ b/app/src/main/java/com/openvehicles/OVMS/api/ApiService.kt @@ -314,7 +314,7 @@ class ApiService : Service(), ApiTask.ApiTaskListener, ApiObserver { try { if (apiTask != null) { Log.v(TAG, "closeConnection: shutting down TCP connection") - apiTask!!.cancel(true) + //apiTask!!.cancel(true) apiTask = null notifyLoggedIn(this, false) sendApiEvent("UpdateStatus") @@ -483,8 +483,26 @@ class ApiService : Service(), ApiTask.ApiTaskListener, ApiObserver { } override fun onPushNotification(msgClass: Char, msgText: String?) { - // This callback only receives MP push notifications for the currently selected vehicle. - // See MyFirebaseMessagingService for system notification broadcasting. + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + // Define the notification channel (required for Android O and above) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val channelName = getString(R.string.app_name) + val channelDescription = "OVMS" + val channel = NotificationChannel("your_channel_id", channelName, NotificationManager.IMPORTANCE_DEFAULT).apply { + description = channelDescription + } + notificationManager.createNotificationChannel(channel) + } + // Create the notification + val notificationBuilder = NotificationCompat.Builder(this, "your_channel_id") + .setSmallIcon(R.drawable.ic_service) + .setContentTitle("OVMS") + .setContentText(msgText ?: msgText) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) + .setAutoCancel(true) + + // Show the notification + notificationManager.notify(1, notificationBuilder.build()) } // ApiObserver interface: