Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Documentation
Sidebar

Getting the Navigation Destination

The GetWayPoints and SubscribeWayPoints RPCs are designed to allow you to get the navigation destination(s) from the active navigation app if the user is navigating.

Checking If Your App Has Permission to Use GetWayPoints

The GetWayPoints and SubscribeWayPoints RPCs are restricted by most vehicle manufacturers. As a result, the head unit you are connecting to will reject the request if you do not have the correct permissions. Please check the Understanding Permissions section for more information on how to check permissions for an RPC.

Checking if Head Unit Supports GetWaypoints

Since there is a possibility that some head units will not support getting the navigation destination, you should check head unit support before attempting to send the request. You should also update your app's UI based on whether or not you can use GetWayPoints.

You can use the SystemCapabilityManager to check the navigation capability returned by Core as shown in the code sample below.

sdlManager.getSystemCapabilityManager().getCapability(SystemCapabilityType.NAVIGATION, new OnSystemCapabilityListener() {
    @Override
    public void onCapabilityRetrieved(Object capability) {
        NavigationCapability navCapability = (NavigationCapability) capability;
        boolean isNavigationSupported = navCapability != null && navCapability.getWayPointsEnabled();
    }

    @Override
    public void onError(String info) {
        HMICapabilities hmiCapabilities = (HMICapabilities) sdlManager.getSystemCapabilityManager().getCapability(SystemCapabilityType.HMI);
        boolean isNavigationSupported = hmiCapabilities.isNavigationAvailable();
    }
});

Subscribing to WayPoints

To subscribe to the waypoints, you will have to set up your callback for whenever the waypoints are updated, then send the SubscribeWayPoints RPC.

Java
// Create this method to receive the subscription callback
sdlManager.addOnRPCNotificationListener(FunctionID.ON_WAY_POINT_CHANGE, new OnRPCNotificationListener() {
    @Override
    public void onNotified(RPCNotification notification) {
        OnWayPointChange onWayPointChangeNotification = (OnWayPointChange) notification;
        //<#Use the waypoint data#>
    }
});

// After SDL has started your connection, at whatever point you want to subscribe, send the subscribe RPC
SubscribeWayPoints subscribeWayPoints = new SubscribeWayPoints();
subscribeWayPoints.setOnRPCResponseListener(new OnRPCResponseListener() {
    @Override
    public void onResponse(int correlationId, RPCResponse rpcResponse) {
        if (rpcResponse.getSuccess()){
            // You are now subscribed!
        } else {
            // Handle the errors
        }
    }

    @Override
    public void onError(int correlationId, Result resultCode, String info) {
        // Handle the errors
    }
});
sdlManager.sendRPC(subscribeWayPoints);

Unsubscribing from Waypoints

To unsubscribe from waypoint data, you must send the UnsubscribeWayPoints RPC.

Java
UnsubscribeWayPoints unsubscribeWayPoints = new UnsubscribeWayPoints();
unsubscribeWayPoints.setOnRPCResponseListener(new OnRPCResponseListener() {
    @Override
    public void onResponse(int correlationId, RPCResponse rpcResponse) {
        if (rpcResponse.getSuccess()){
            // You are now unsubscribed!
        } else {
            // Handle the errors
        }
    }

    @Override
    public void onError(int correlationId, Result resultCode, String info) {
        // Handle the errors
    }
});
sdlManager.sendRPC(unsubscribeWayPoints);

One-Time Waypoints Request

If you only need waypoint data once without an ongoing subscription, you can use GetWayPoints instead of SubscribeWayPoints.

Java
GetWayPoints getWayPoints = new GetWayPoints();
getWayPoints.setOnRPCResponseListener(new OnRPCResponseListener() {
    @Override
    public void onResponse(int correlationId, RPCResponse rpcResponse) {
        if (rpcResponse.getSuccess()){
            GetWayPointsResponse getWayPointsResponse = (GetWayPointsResponse) rpcResponse;
            <#Use the waypoint information#>
        } else {
            // Handle the errors
        }
    }

    @Override
    public void onError(int correlationId, Result resultCode, String info) {
        // Handle the errors
    }
});
sdlManager.sendRPC(getWayPoints);
View on GitHub.com
Previous Section Next Section