Android_SmartDeviceLink _Get Vehicle Data

我的博客

获取车机数据

使用getvehicle - data RPC请求获取车辆数据。为了获取数据,HMI级别必须是完整的、有限的或背景。
每个汽车制造商决定它将公开哪些数据。请检查OnPermissionsChange RPC通知,以查明您将在您的head单元中访问哪些数据

注意:您可能只要求对您的appName可用的车辆数据。这些将分别由每个OEM(.原始设备制造商)指定。

Single Time Vehicle Data Retrieval单次车辆数据查询

使用getvehicle数据,我们可以在需要的情况下,一次询问车辆数据。

GetVehicleData vdRequest = new GetVehicleData();
vdRequest.setPrndl(true);
vdRequest.setOnRPCResponseListener(new OnRPCResponseListener() {
    @Override
    public void onResponse(int correlationId, RPCResponse response) {
        if(response.getSuccess()){
            PRNDL prndl = ((GetVehicleDataResponse) response).getPrndl();
            Log.i("SdlService", "PRNDL status: " + prndl.toString());
        }else{
            Log.i("SdlService", "GetVehicleData was rejected.");
        }
    }
});
try {
    proxy.sendRPCRequest(vdRequest);
} catch (SdlException e) {
    e.printStackTrace();
}

Subscribing to Vehicle Data 订阅车机数据

订阅车辆数据可以让您在有新数据时得到通知。这些数据不应以一致的方式接收。新的车辆数据大约每秒钟都能得到。
首先,发送订阅车辆数据请求。

SubscribeVehicleData subscribeRequest = new SubscribeVehicleData();
subscribeRequest.setPrndl(true);
subscribeRequest.setOnRPCResponseListener(new OnRPCResponseListener() {
    @Override
    public void onResponse(int correlationId, RPCResponse response) {
        if(response.getSuccess()){
            Log.i("SdlService", "Successfully subscribed to vehicle data.");
        }else{
            Log.i("SdlService", "Request to subscribe to vehicle data was rejected.");
        }
    }
});
 
try {
    proxy.sendRPCRequest(subscribeRequest);
} catch (SdlException e) {
    e.printStackTrace();
}

然后,您将能够在OnVehicleData通知中观察到新的数据:

@Override
public void onOnVehicleData(OnVehicleData notification) {
    PRNDL prndl = notification.getPrndl();
    Log.i("SdlService", "PRNDL status was updated to: " prndl.toString());
}

Unsubscribing from Vehicle Data取消订阅车机数据

有时你可能并不总是需要你监听的所有车辆数据。我们建议您只在需要车辆数据时才订阅。要停止收听特定的车辆数据项,请使用UnsubscribeVehicleData

UnsubscribeVehicleData unsubscribeRequest = new UnsubscribeVehicleData();
unsubscribeRequest.setPrndl(true); // unsubscribe to PRNDL data
unsubscribeRequest.setOnRPCResponseListener(new OnRPCResponseListener() {
    @Override
    public void onResponse(int correlationId, RPCResponse response) {
        if(response.getSuccess()){
            Log.i("SdlService", "Successfully unsubscribed to vehicle data.");
        }else{
            Log.i("SdlService", "Request to unsubscribe to vehicle data was rejected.");
        }
    }
});
 
try {
    proxy.sendRPCRequest(unsubscribeRequest);
} catch (SdlException e) {
    e.printStackTrace();
}

你可能感兴趣的:(Android_SmartDeviceLink _Get Vehicle Data)