So in my app I allow the user to record their screen, for ease of use I am making use of the HBRecorder Library. For Android 14+ you need to declare foreground services in your manifest and request permissions from the user. I have done this but I am getting policy warnings from google(Also Below). What am I missing? as if I remove any of these permissions I get a security exception on Android 14 devices.
The video I uploaded for google clearly shows that the user gets prompted if they want to record the screen and the message explains why, and it also shows that the recording is only active while in the activity.
So I am obviously missing something,has anyone run into this yet?
//Manifest Permissions
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.android.permission.CAPTURE_VIDEO_OUTPUT" />
//Function requesting permission
`fun requestPermissions(activity: Activity) {
val permissions = mutableListOf<String>()
permissions.add(Manifest.permission.CAMERA)
permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE)
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
permissions.add(Manifest.permission.RECORD_AUDIO)
permissions.add(Manifest.permission.ACCESS_MEDIA_LOCATION)
permissions.add(Manifest.permission.CAPTURE_AUDIO_OUTPUT)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
permissions.add(Manifest.permission.MANAGE_EXTERNAL_STORAGE)
> }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissions.add(Manifest.permission.READ_MEDIA_VIDEO)
> }
if (Build.VERSION.SDK_INT >= 34) {
permissions.add(Manifest.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION)
permissions.add(Manifest.permission.FOREGROUND_SERVICE)
> }`
//function to start recording
` fun startRecordingScreen() {
val mediaProjectionManager =
getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
val permissionIntent = mediaProjectionManager.createScreenCaptureIntent()
startActivityForResult(permissionIntent!!, SCREEN_RECORD_REQUEST_CODE)
btnRecordMain.setBackgroundResource(R.drawable.btnrecordd)
}`
I've removed the permissions for foreground services and then Google removes the policy warnings, problem is on Android 14 devices I get the below exception if I remove any of the 3 permissions.
I have removed one at a time and tested on Android 14 devices and every single time crash.
java.lang.SecurityException:
at android.os.Parcel.createExceptionOrNull (Parcel.java:3069)
at android.os.Parcel.createException (Parcel.java:3053)
at android.os.Parcel.readException (Parcel.java:3036)
at android.os.Parcel.readException (Parcel.java:2978)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground (IActivityManager.java:7214)
at android.app.Service.startForeground (Service.java:775)
at com.hbisoft.hbrecorder.ScreenRecordService.onStartCommand (ScreenRecordService.java:234)
at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:5268)`
`
I can't see you call
Activity.requestPermissions. You build a list of perms but don't ask for them in a func of the same name - this is not the same thing. You then have to wait for Activity.onRequestPermissionsResult