Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions app/src/main/java/com/openvehicles/OVMS/api/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down