Mobile Navigation手機導航和視頻流
移動導航允許地圖合作伙伴將他們的應用程序帶到汽車中,并顯示他們的地圖,然后方便地轉(zhuǎn)向用戶。這個特性在head單元上的行為與普通應用程序不同。主要的差異是
導航應用程序不使用基本的屏幕模板。他們的主要視圖是來自設備的視頻流。
導航應用程序可以通過二進制流發(fā)送音頻。這將減弱當前音頻源,并且應該用于導航命令。
導航應用程序可以接收來自視頻流的觸摸事件。
注意:為了使用SDL的移動導航功能,應用程序必須具備Android 4.4 (SDK 19)的最低要求。這是由于使用了Android提供的視頻編碼器。
和儷安的車機版本號是4.2.2(SDK 17),低于要求的19.
Connecting an app
導航應用程序的第一個不同之處在于,必須在SdlProxyALM的創(chuàng)建中設置導航應用程序的appHMIType。導航應用也是非媒體應用。第二個區(qū)別是需要在SdlProxyBuilder中設置的名為securitymanager的屬性。如果連接到需要安全視頻的核心版本。此屬性需要一系列安全管理器類,它們將繼承自SdlSecurityBase類。這些安全庫由OEMs自己提供,只適用于OEM。這里沒有一個通用的安全庫。
SdlProxyBuilder.Builder builder = new SdlProxyBuilder.Builder(this,APP_ID, APP_NAME, false, getApplicationContext());
Vector<AppHMIType> hmiTypes = new Vector<AppHMIType>();
hmiTypes.add(AppHMIType.NAVIGATION);
builder.setVrAppHMITypes(hmiTypes);
List<? extends SdlSecurityBase> securityManagers = new ArrayList();
securityManagers.add(OEMSecurityManager1.class);
securityManagers.add(OEMSecurityManager1.class);
builder.setSdlSecurity(securityManagers);
proxy = builder.build();
注意:在編譯時,您必須確保包含您希望支持的所有可能的OEM安全管理器。
注冊后,應用程序?qū)㈤_始接收回調(diào)。一個重要的回調(diào)是onOnHMIStatus,它通知應用程序在head單元上當前可見的應用程序。在注冊后,hmiLevel將為NONE或BACKGROUND。一旦hmiLevel被head單元設置為FULL,就應該開始流通。
視頻輸出流
為了從SDL應用程序獲取流視頻,我們只需要管理一些事情。但是在大多數(shù)情況下,庫將處理執(zhí)行視頻流的大部分邏輯。
SDLProxyALM
重要的是,我們要創(chuàng)建SDLProxyALM實例,并使用正確的設置來流視頻。這已經(jīng)涵蓋了移動導航>的介紹。
SDL Remote Display
SdlRemoteDisplay基類提供了使用SDL開始流的最簡單方法。SdlRemoteDisplay由Android的presentation類擴展,并與SDL Android庫的其他方面進行了修改。
注意:建議您將其擴展為在服務中使用SDLProxyALM實例的本地類。
擴展這個類給開發(fā)人員提供了一個熟悉的、本地的經(jīng)驗來處理屏幕上的布局和事件。
public static class MyDisplay extends SdlRemoteDisplay{
public MyDisplay(Context context, Display display) {
super(context, display);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sdl);
final Button button1 = (Button) findViewById(R.id.button_1);
button1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "Received motion event for button1");
}
});
}
}
Managing the Stream
要啟動流的惟一方法是將SDLProxyALM實例與SdlRemoteDisplay的擴展結(jié)合起來。當應用程序在onOnHMIStatus(OnHMIStatus通知)回調(diào)中收到它的第一個HMI_FULL狀態(tài)時,就會發(fā)生這種情況。需要調(diào)用的方法是startRemoteDisplayStream
@Override
public void onOnHMIStatus(OnHMIStatus notification) {
if(notification.getHmiLevel().equals(HMILevel.HMI_FULL)){
if (notification.getFirstRun()) {
proxy.startRemoteDisplayStream(getApplicationContext(), MyDisplay.class, null, false);
}
}
}
Ending the Stream
當HMIStatus返回到HM_NONE時,是時候停止流了。這是通過SDLProxyALM中的方法stopRemoteDisplayStream()實現(xiàn)的。