diff --git a/app/build.gradle b/app/build.gradle index 5ff89f2..91297e5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,12 +7,12 @@ plugins { android { namespace 'com.example.fishjamandroidexample' - compileSdk 33 + compileSdk 34 defaultConfig { applicationId "com.example.fishjamandroidexample" minSdk 24 - targetSdk 33 + targetSdk 34 versionCode 1 versionName "1.0" @@ -57,7 +57,7 @@ android { dependencies { - implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.core:core-ktx:1.13.1' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' implementation 'androidx.activity:activity-compose:1.7.1' implementation platform('androidx.compose:compose-bom:2022.10.00') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eba6f96..b8f968a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,18 @@ + xmlns:tools="http://schemas.android.com/tools" > + + + + + + + + + + + tools:targetApi="31" > + + + = Build.VERSION_CODES.O) { + val name = "Fishjam notification channel" + val importance = NotificationManager.IMPORTANCE_DEFAULT + val mChannel = NotificationChannel(channelID, name, importance) + val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager + notificationManager.createNotificationChannel(mChannel) + } + val notification = + NotificationCompat.Builder(this, channelID) + .setContentTitle("Fishjam is running") + .build() + ServiceCompat.startForeground( + this, + 100, + notification, + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA + } else { + 0 + } + ) + } catch (e: Exception) { + Timber.w("Failed to start foreground service") + } + } + + override fun onStartCommand( + intent: Intent?, + flags: Int, + startId: Int + ): Int { + startForeground() + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } +} diff --git a/app/src/main/java/com/example/fishjamandroidexample/MainActivity.kt b/app/src/main/java/com/example/fishjamandroidexample/MainActivity.kt index a23d97d..0e52169 100644 --- a/app/src/main/java/com/example/fishjamandroidexample/MainActivity.kt +++ b/app/src/main/java/com/example/fishjamandroidexample/MainActivity.kt @@ -102,7 +102,8 @@ class MainActivity : ComponentActivity() { rememberMultiplePermissionsState( listOf( Manifest.permission.RECORD_AUDIO, - Manifest.permission.CAMERA + Manifest.permission.CAMERA, + Manifest.permission.POST_NOTIFICATIONS ) ) diff --git a/app/src/main/java/com/example/fishjamandroidexample/RoomViewModel.kt b/app/src/main/java/com/example/fishjamandroidexample/RoomViewModel.kt index 193cbfb..a22c37d 100644 --- a/app/src/main/java/com/example/fishjamandroidexample/RoomViewModel.kt +++ b/app/src/main/java/com/example/fishjamandroidexample/RoomViewModel.kt @@ -1,6 +1,8 @@ package com.example.fishjamandroidexample import android.app.Application +import android.content.Intent +import android.os.Build import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.fishjamdev.client.Config @@ -40,6 +42,15 @@ class RoomViewModel(application: Application) : setupTracks() } + override fun onCleared() { + super.onCleared() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val intent = + Intent(getApplication().applicationContext, CameraService::class.java) + getApplication().applicationContext.stopService(intent) + } + } + fun disconnect() { localVideoTrack?.stop() localVideoTrack = null @@ -75,6 +86,10 @@ class RoomViewModel(application: Application) : ) } emitParticipants() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val intent = Intent(getApplication().applicationContext, CameraService::class.java) + getApplication().applicationContext.startForegroundService(intent) + } } override fun onJoinError(metadata: Any) {