Skip to content

ServiceAttribute is missing foregroundServiceType #3712

Description

@Cheesebaron

Android API 29 introduced foregroundServiceType on Services to classify what kind of service it is. Kind of like on iOS, for background downloads, music etc.

This attribute is needed in the AndroidManifest.xml when targeting API 29 (Android Q), when wanting to distinguish between stuff like Foreground Location updates and Background Location updates.

Steps to Reproduce

  1. Add [Service] to your Service class.
  2. Explore the properties exposed

Expected Behavior

I would expect ForegroundServiceType and some kind of enum would be available when TargetFrameworkVersion is set to v10.0 in the csproj

Actual Behavior

No ForegroundServiceType is available

Version Information

Visual Studio Community 2019 for Mac
Version 8.3 (build 1805)

Xamarin.Android
Version: 10.0.0.43 (Visual Studio Community)
Commit: xamarin-android/d16-3/8af1ca8
Android SDK: /Users/cheesebaron/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.4
SDK Build Tools Version: 29.0.0

Activity

  1. Cheesebaron commented on Oct 1, 2019

    @Cheesebaron
    Author

    Workaround right now is to remove [Service] from your service and add it manually to the AndroidManifest.

  2. added this to the d16-4 milestone on Oct 2, 2019
  3. gugavaro commented on Oct 15, 2019

    @gugavaro
    Contributor

    Hi @Cheesebaron can you please provide a project that repros it?
    thanks,
    Gustavo.

  4. Cheesebaron commented on Oct 16, 2019

    @Cheesebaron
    Author

    ServiceTypeTest.zip

    I've attached a project.

    Using the ServiceAttribute as seen on MyService, there is no way to specify ForegroundServiceType as that property does not exist.

    The workaround is to manually register the service in the manifest as seen for MyService2.

  5. gugavaro commented on Oct 16, 2019

    @gugavaro
    Contributor

    Thank you @Cheesebaron
    I will take a look on it.

    Gustavo.

  6. chrisfoulds commented on Nov 12, 2019

    @chrisfoulds

    How would I declare manually for a Xamarin forms project ? , is there an ETA for this being added ?

  7. Cheesebaron commented on Nov 12, 2019

    @Cheesebaron
    Author

    @chrisfoulds remove the [Service] attribute on your service and add the entry to your AndroidManifest.xml file yourself. See the attatched ServiceTypeTest.zip for an example.

  8. chrisfoulds commented on Nov 12, 2019

    @chrisfoulds

    @Cheesebaron I tried that and it didn't work which is why I asked.

    I added :
    <service android:name="com.abc.testapp.TimestampService" />

    Yet the autogenerated one using [Service] comes out as :
    <service android:name="md586c6802ef9432e3426afeadf29df91ef.TimestampService" />

    So quite different locations

  9. Cheesebaron commented on Nov 12, 2019

    @Cheesebaron
    Author

    Add the [Register("com.abc.testapp.TimestampService")] on your Service.

  10. chrisfoulds commented on Nov 16, 2019

    @chrisfoulds

    @Cheesebaron thanks, worked a treat wasn't aware of that one.

  11. brendanzagaeski commented on Jan 23, 2020

    @brendanzagaeski
    Contributor

    Release status update

    A new Preview version has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

    Fix included in Xamarin.Android 10.2.0.84.

    Fix included on Windows in Visual Studio 2019 version 16.5 Preview 2. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

    Fix included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

  12. brendanzagaeski commented on Mar 17, 2020

    @brendanzagaeski
    Contributor

    Release status update

    A new Release version has now been published on Windows that includes the fix for this item. The fix is not yet published in a Release version on macOS. I will update this item again when a Release version is available on macOS that includes the fix.

    Fix included in Xamarin.Android 10.2.0.100.

    Fix included on Windows in Visual Studio 2019 version 16.5. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.

    (Fix also included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.)

  13. brendanzagaeski commented on Mar 24, 2020

    @brendanzagaeski
    Contributor

    Release status update

    A new Release version has now been published on macOS that includes the fix for this item.

    Fix included in Xamarin.Android 10.2.0.100.

    Fix included on macOS in Visual Studio 2019 for Mac version 8.5. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

    (Fix also included on Windows in Visual Studio 2019 version 16.5 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)

  14. unamed000 commented on Jan 11, 2021

    @unamed000

    I'm not able to find this attribute in the latest stable version of Xamarin.Android. Anyone has any ideas?

    EDIT: Nevermind, I have to exit VS again after switching to API Target 29 to be able to see that new attribute

  15. ghost locked as resolved and limited conversation to collaborators on Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions