Skip to content

Unable to set up "special use" foreground service via ServiceAttribute #8409

@tipa

Description

@tipa

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS2022, NET8 RC1

Description

While migrating my app to target API 34, I want to set up a Service using the special use type as foreground service type (this type is new in Android 14): https://developer.android.com/about/versions/14/changes/fgs-types-required#special-use

Steps to Reproduce

Added permission to AndroidManifest.xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

Added service type to Service attribute

[Service(ForegroundServiceType = Android.Content.PM.ForegroundService.TypeSpecialUse)]
sealed class MyService : Service
{
}

Resulting Android.xml in \obj\Debug\net8.0-android

<service android:foregroundServiceType="" android:name="crc64cd18cf298694e84d.MyService " />
Note that it has an empty string as foregroundServiceType, instead of specialUse.

Additionally, there is no way to specify the required property with PROPERTY_SPECIAL_USE_FGS_SUBTYPE on the attribute

Did you find any workaround?

I was able to workaround the problem by manually adding the service tag in the AndroidManifex.xml and giving my Service an explicit name

<service android:foregroundServiceType="specialUse" android:name="my.app.MyService">
   <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
             android:value="Explanation on why I am using this service type"/>
</service>
[Service(Name = "my.app.MyService")]
sealed class FocusSessionService : Service
{ 
}

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions