Skip to content

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

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

Activity

  1. added
    Area: App+Library BuildIssues when building Library projects or Application projects.
    and removed
    needs-triageIssues that need to be assigned.
    on Oct 10, 2023
  2. dellis1972 commented on Oct 11, 2023

    @dellis1972
    Contributor

    @tipa

    We fixed the foregroundServiceType being blank issue via #8412 .

    The other issue is a bit more of a problem. We are talking about how to implement that.

  3. locked and limited conversation to collaborators on Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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