Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
Android Guides
Adapting to the Head Unit Language

Adapting to the Head Unit Language

Since a head unit can support multiple languages, you may want to add support for more than one language to your SDL app. The SDL library allows you to check which language is currently used by the head unit. If desired, the app's name and the app's text-to-speech (TTS) name can be customized to reflect the head unit's current language. If your app name is not part of the current lexicon, you should tell the VR system how a native speaker will pronounce your app name by setting the TTS name using phonemes from either the Microsoft SAPI phoneme set or from the LHPLUS phoneme set.

Setting the Default Language

The initial configuration of the SdlManager requires a default language when setting the Builder. If not set, the SDL library uses American English (EN_US) as the default language. The connection will fail if the head unit does not support the language set in the Builder. The RegisterAppInterface response RPC will return INVALID_DATA as the reason for rejecting the request.

What if My App Does Not Support the Head Unit Language?

If your app does not support the current head unit language, you should decide on a default language to use in your app. All text should be created using this default language. Unfortunately, your VR commands will probably not work as the VR system will not recognize your users' pronunciation.

Handling a Language Change

When a user changes the language on a head unit, an OnLanguageChange notification will be sent from Core, causing your app will disconnect. In order for your app to automatically reconnect to the head unit, there are a few changes to make in the following files:

  • Local SDL Service
  • Local SDL Broadcast Receiver

SDL Service

We want to tell our local SDL Broadcast Receiver to restart the service when an OnLanguageChange notification is received from Core . To do so, add a notification listener as follows:

sdlManager.addOnRPCNotificationListener(FunctionID.ON_LANGUAGE_CHANGE, new OnRPCNotificationListener() {
    @Override
    public void onNotified(RPCNotification notification) {
        SdlService.this.stopSelf();
        Intent intent = new Intent(TransportConstants.START_ROUTER_SERVICE_ACTION);
        intent.putExtra(SdlReceiver.RECONNECT_LANG_CHANGE, true);
        AndroidTools.sendExplicitBroadcast(context, intent, null);
    }
});

SDL Broadcast Receiver

When the SDL Service's connection to core is closed, we want to tell our local SDL Broadcast Receiver to restart the SDL Service. To do this, first add a public String in your app's local SDL Broadcast Receiver class that can be included as an extra in a broadcast intent.

public static final String RECONNECT_LANG_CHANGE = "RECONNECT_LANG_CHANGE";

Then, override the onReceive() method of the local SDL Broadcast Receiver to call onSdlEnabled() when receiving that action:

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent); // Required if overriding this method

    if (intent != null) {
        String action = intent.getAction();
        if (action != null){
            if(action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION)) {
                if (intent.getBooleanExtra(RECONNECT_LANG_CHANGE, false)) {
                    onSdlEnabled(context, intent);
                }
            }
        }
    }
}
Must

Be sure to call super.onReceive(context, intent); at the start of the method!

Note

This guide also assumes your local SDL Broadcast Receiver implements the onSdlEnabled() method as follows:

@Override
public void onSdlEnabled(Context context, Intent intent) {
    intent.setClass(context, SdlService.class);
    context.startService(intent);
}
View on GitHub.com
Previous Section Next Section