Skip to content

Commit f9fe441

Browse files
committed
Added Android Auto notification support.
Signed-off-by: Jens Zalzala <jens@shakingearthdigital.com>
1 parent 6bc1fc7 commit f9fe441

File tree

4 files changed

+69
-13
lines changed

4 files changed

+69
-13
lines changed

SETUP.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ This requires a working Internet connection.
106106

107107
The generated APK file is saved in ```app/build/outputs/apk``` as ```app-generic-debug.apk```.
108108

109+
### Working with Android Auto
110+
111+
To test [notification extension to Android Auto](https://developer.android.com/training/cars/communication/notification-messaging), Developer settings and Unknown sources need to be enabled in
112+
the Android Auto settings:
113+
114+
1. Open the Settings app on your device
115+
2. Search for Android Auto, or click on Connected Devices > Android Auto
116+
3. Scroll all the way down to Version, and click it 10 times to enable Developer settings
117+
4. Click the 3 dots in the top right and select Developer settings
118+
5. Enable Unknown sources
119+
120+
You can now receive notifications on Android Auto from a Nextcloud Talk development build.
121+
109122
### App flavours
110123

111124
The app is currently equipped to be built with three flavours:

app/src/main/AndroidManifest.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@
9999

100100
<meta-data
101101
android:name="android.max_aspect"
102-
android:value="10" />
102+
android:value="10"/>
103+
104+
<meta-data
105+
android:name="com.google.android.gms.car.application"
106+
android:resource="@xml/automotive_app_desc"/>
103107

104108
<activity
105109
android:name=".activities.MainActivity"
@@ -291,10 +295,18 @@
291295
</intent-filter>
292296
</receiver>
293297

294-
<receiver android:name=".receivers.DirectReplyReceiver" />
295-
<receiver android:name=".receivers.MarkAsReadReceiver" />
296-
<receiver android:name=".receivers.DismissRecordingAvailableReceiver" />
297-
<receiver android:name=".receivers.ShareRecordingToChatReceiver" />
298+
<receiver
299+
android:name=".receivers.DirectReplyReceiver"
300+
android:exported="false" />
301+
<receiver
302+
android:name=".receivers.MarkAsReadReceiver"
303+
android:exported="false" />
304+
<receiver
305+
android:name=".receivers.DismissRecordingAvailableReceiver"
306+
android:exported="false" />
307+
<receiver
308+
android:name=".receivers.ShareRecordingToChatReceiver"
309+
android:exported="false" />
298310

299311
<service
300312
android:name=".utils.SyncService"

app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
685685
}
686686

687687
private fun styleImageNotification(notificationBuilder: NotificationCompat.Builder) {
688+
val notificationUser = pushMessage.notificationUser
689+
val senderName = notificationUser?.name ?: ""
690+
val conversationTitle = pushMessage.subject.ifEmpty { senderName }
691+
688692
val bitmap = loadImageBitmapSync(imagePreviewUrl!!)
689693
if (bitmap != null) {
690694
notificationBuilder
@@ -693,6 +697,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
693697
NotificationCompat.BigPictureStyle()
694698
.bigPicture(bitmap)
695699
.bigLargeIcon(null as Bitmap?)
700+
.setBigContentTitle(conversationTitle)
696701
)
697702
}
698703
}
@@ -744,10 +749,19 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
744749
}
745750
person.setIcon(loadAvatarSync(avatarUrl, context!!))
746751
}
747-
notificationBuilder.setStyle(getStyle(person.build(), style))
752+
val deviceUser = Person.Builder()
753+
.setKey(signatureVerification.user!!.id.toString() + "@" + signatureVerification.user!!.userId)
754+
.setName(signatureVerification.user!!.displayName ?: signatureVerification.user!!.userId ?: "You")
755+
.build()
756+
notificationBuilder.setStyle(getStyle(deviceUser, person.build(), style))
748757
}
749758

750-
private fun buildIntentForAction(cls: Class<*>, systemNotificationId: Int, messageId: Int): PendingIntent {
759+
private fun buildIntentForAction(
760+
cls: Class<*>,
761+
systemNotificationId: Int,
762+
messageId: Int,
763+
mutable: Boolean = true
764+
): PendingIntent {
751765
val actualIntent = Intent(context, cls)
752766

753767
// NOTE - systemNotificationId is an internal ID used on the device only.
@@ -758,7 +772,8 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
758772
actualIntent.putExtra(KEY_MESSAGE_ID, messageId)
759773

760774
val intentFlag: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
761-
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
775+
val mutabilityFlag = if (mutable) PendingIntent.FLAG_MUTABLE else PendingIntent.FLAG_IMMUTABLE
776+
mutabilityFlag or PendingIntent.FLAG_UPDATE_CURRENT
762777
} else {
763778
PendingIntent.FLAG_UPDATE_CURRENT
764779
}
@@ -777,7 +792,8 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
777792
val pendingIntent = buildIntentForAction(
778793
MarkAsReadReceiver::class.java,
779794
systemNotificationId,
780-
messageId
795+
messageId,
796+
mutable = false
781797
)
782798
val markAsReadAction = NotificationCompat.Action.Builder(
783799
R.drawable.ic_mark_chat_read_24px,
@@ -887,9 +903,13 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
887903
notificationBuilder.addAction(shareRecordingAction)
888904
}
889905

890-
private fun getStyle(person: Person, style: NotificationCompat.MessagingStyle?): NotificationCompat.MessagingStyle {
891-
val newStyle = NotificationCompat.MessagingStyle(person)
892-
newStyle.conversationTitle = pushMessage.subject
906+
private fun getStyle(
907+
deviceUser: Person,
908+
sender: Person,
909+
style: NotificationCompat.MessagingStyle?
910+
): NotificationCompat.MessagingStyle {
911+
val newStyle = NotificationCompat.MessagingStyle(deviceUser)
912+
newStyle.conversationTitle = pushMessage.subject.ifEmpty { sender.name }
893913
newStyle.isGroupConversation = "one2one" != conversationType
894914
style?.messages?.forEach(
895915
Consumer { message: NotificationCompat.MessagingStyle.Message ->
@@ -902,7 +922,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
902922
)
903923
}
904924
)
905-
newStyle.addMessage(pushMessage.text, pushMessage.timestamp, person)
925+
newStyle.addMessage(pushMessage.text, pushMessage.timestamp, sender)
906926
return newStyle
907927
}
908928

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Nextcloud Talk - Android Client
3+
~
4+
~ SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
~ SPDX-License-Identifier: GPL-3.0-or-later
6+
~ SPDX-FileCopyrightText: 2026 Jens Zalzala <jens@shakingearth.digital>
7+
-->
8+
9+
<automotiveApp>
10+
<uses name="notification" />
11+
</automotiveApp>

0 commit comments

Comments
 (0)