Skip to content

Commit

Permalink
[example] Fix crash when run on Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
littleGnAl committed Aug 20, 2024
1 parent 8d85a96 commit 0be6ccd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package="io.agora.agora_rtc_ng_example">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:label="agora_rtc_ng_example"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Binder
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -89,7 +90,14 @@ class ExampleService: Service() {
.setContentIntent(getContentIntent())
.setShowWhen(false)

startForeground(NOTIFICATION_ID_DAEMON_SERVICE, notificationBuilder.build())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
startForeground(
NOTIFICATION_ID_DAEMON_SERVICE,
notificationBuilder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE xor ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
} else {
startForeground(NOTIFICATION_ID_DAEMON_SERVICE, notificationBuilder.build())
}
}

private fun getContentIntent(): PendingIntent? {
Expand Down

0 comments on commit 0be6ccd

Please sign in to comment.