[null, null, null, {"document_url": "https://smartdevicelink.com/en/guides/android/migrating-to-newer-sdl-android-versions/updating-to-45/", "unformatted_src": "https://d83tozu1c8tt6.cloudfront.net/media/builds/master/5/b11a556112944eb841f23ccaf810ed032342c0fa/migrating-to-newer-sdl-android-versions/updating-to-45/assets/silent_notifications.png", "src": "https://d83tozu1c8tt6.cloudfront.net/media/builds/master/5/b11a556112944eb841f23ccaf810ed032342c0fa/migrating-to-newer-sdl-android-versions/updating-to-45/assets/silent_notifications.png", "formatted_filename": "silent notifications", "alt_text": "Silent Notifications"}, null, {"document_url": "https://smartdevicelink.com/en/guides/android/migrating-to-newer-sdl-android-versions/updating-to-45/", "unformatted_src": "https://d83tozu1c8tt6.cloudfront.net/media/builds/master/5/b11a556112944eb841f23ccaf810ed032342c0fa/migrating-to-newer-sdl-android-versions/updating-to-45/assets/invis_notifications.png", "src": "https://d83tozu1c8tt6.cloudfront.net/media/builds/master/5/b11a556112944eb841f23ccaf810ed032342c0fa/migrating-to-newer-sdl-android-versions/updating-to-45/assets/invis_notifications.png", "formatted_filename": "invis notifications", "alt_text": "Invisible Notifications"}, null]
Android Documentation
English 简体中文

Updating from 4.4 to 4.5

This guide is to help developers get setup with the SDL Android library 4.5. It is assumed that the developer is already updated to 4.4 of the library. There are a few very important changes that we need to make to the integration to keep things working well. The first is a few new additions to the AndroidManifest.xml and the SdlRouterService entry. Next, we have to prepare for Android Oreo's push towards foreground services.

We will make changes to:

AndroidManifest.xml Updates

Assuming the manifest was up to date with version 4.4 requirements we need to add an intent-filter and a meta-data item. The entire entry should look as follows:

Intent Filter

The new versions of the SDL Android library rely on the com.smartdevicelink.router.service action to query SDL enabled apps that host router services. This allows the library to determine which router service to start. This intent-filter MUST be included.


Router Service Version

Adding the sdl_router_service_version metadata allows the library to know the version of the router service that the app is using. This makes it simpler for the library to choose the newest router service when multiple router services are available.

Custom Router Service This is only for specific OEM applications, therefore normal developers do not need to worry about this.

Some OEMs choose to implement custom router services. Setting the sdl_router_service_is_custom_name metadata value to true means that the app is using something custom over the default router service that is included in the SDL Android library. Do not include this meta-data entry unless you know what you are doing.

Android Oreo's Push To Foreground Services

Previous versions of Android allowed our SDL app partners to start their SDL services in the background and attach themselves to the foregrounded SDL router service. Android Oreo (API 26) has changed that. Due to new OS limitations, apps must start their SDL service in the foreground.


There are a few changes to make, one in the SdlBroadcastReceiver and the other in the SdlService (or which service the proxy is implemented).



Sample Update

This means the app will start the SDL service in the background if we are on a device that uses Android N or earlier. If the app is running on Android Oreo or newer, the service will make a promise to the OS that the service will move into the foreground. If the service doesn't explicitly move into the foreground an exception will be thrown.

SdlService (Or similar)

Within the SdlService class or similar you will need to add a call to start the service in the foreground. This will include creating a notification to sit in the status bar tray. This information and icons should be relevant for what the service is doing/going to do. If you already start your service in the foreground, you can ignore this section.

Exiting the Foreground

It's important that you don't leave you notification in the notification tray as it is very confusing to users. So in the onDestroy method in your service, simply call the stopForeground method.

Notification Suggestions

We realize that pushing a notification to the notification tray is not ideal for any apps, but with Android's push for more transparency to users it's important that we don't try to workaround that. Android is getting stricter with their guidelines and could potentially prevent apps from being released if they are found to be not adhering to these rules.

The Correct way

The right way to handle the new foreground service requirement is to simply push a full fledged notification to the notification tray.


The Not So Correct Way

Currently Android Oreo allows a notification to be used that has not declared a notification channel. This results in the notification icon not actually appearing on its own. Instead it is grouped together into the notification channel that reads "# apps are using battery" from the Android System. This is likely to prevent breaking changes from apps that have not updated their integration to Android Oreo, however, we fully anticipate this to be changed in the future so it is not recommended.


How it looks The Absolutely Not Correct Way

It is possible to create a somewhat invisible notification. This will appear to just be blank space in the notification tray. With adding minimal content to the notification when the user pulls down the tray it will have a very small footprint on the screen. However, this is completely disingenuous to the user and should not be considered a solution. Android will most likely see this as bad behavior and could prevent you from releasing your app or even remove your app from the play store with a ban included. Don't do this.

 View on GitHub.com