新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Android 4.2 Wifi Display 之 Settings 源碼分析

Android 4.2 Wifi Display 之 Settings 源碼分析

作者: 時(shí)間:2016-10-08 來(lái)源:網(wǎng)絡(luò) 收藏

一、簡(jiǎn)單背景

本文引用地址:http://www.2s4d.com/article/201610/305680.htm

簡(jiǎn)單背景:隨著無(wú)線互聯(lián)的深入,不管是藍(lán)牙、WIFI或者各種基于此的規(guī)范不管是UPNP還是DLNA都隨著用戶的需求得到了很大的發(fā)展,google 自從android 4.0引入wifi direct后,又在11月份公布的android 4.2中引入了Miracast無(wú)線顯示共享,其協(xié)議在此可以下載。具體的協(xié)議部分內(nèi)容比較多,本人由于水平有限,就不在這里羅列協(xié)議的內(nèi)容了,只附上一份架構(gòu)圖供大家對(duì)其有個(gè)大致的印象。

英文縮寫(xiě)對(duì)應(yīng)如下:

HIDC: Human Interface Device Class

UIBC: User Input Back Channel

PES: Packetized Elementary Stream

HDCP: High-bandwidth Digital Content Protection

MPEG2-TS: Moving Picture Experts Group 2 Transport Stream

RTSP: Real-Time Streaming Protocol

RTP: Real-time Transport Protocol

Wi-Fi P2P: Wi-Fi Direct

TDLS: Tunneled Direct Link Setup

二、應(yīng)用層簡(jiǎn)介

好了,接下來(lái)首先來(lái)看一看android 4.2 提供了哪些與其相關(guān)的應(yīng)用:

首先,需要注意的自然是API文檔中公布的 http://developer.android.com/about/versions/android-4.2.html#SecondaryDisplays

Presentation應(yīng)用,在源碼中路徑為:development/samples/ApiDemos/src/com/example/android/apis/app/下面的兩個(gè)文件

PresentationActivity.java

以及 PresentationWithMediaRouterActivity.java 。

這兩個(gè)應(yīng)用所使用的Presentation基類在frameworks/base/core/java/android/app/Presentation.java,可以看到其繼承了dialog類,并復(fù)用了如show()以及cancel()函數(shù)。

由于官方文檔已經(jīng)有了關(guān)于Presentation以及MediaRouter的簡(jiǎn)要介紹,這里先不再結(jié)合framework層詳細(xì)介紹,以后有機(jī)會(huì)一并再結(jié)合源碼分析一下。

簡(jiǎn)單來(lái)說(shuō),Display Manager 可以列舉出可以直連顯示的多個(gè)設(shè)備,MediaRouter提供了快速獲得系統(tǒng)中用于演示(presentations)默認(rèn)顯示設(shè)備的方法。可以利用

frameworks/base/media/java/android/media /MediaRouter.java下的getSelectedRoute(int type){ }函數(shù)來(lái)獲得當(dāng)前所選擇type類型的Router信息。對(duì)于PresentationWithMediaRouterActivity應(yīng)用而言,

[java] view plaincopy

MediaRouter mMediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);

MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);

Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;

可以看到這里傳入的是ROUTE_TYPE_LIVE_VIDEO類型,供其獲取已選擇的 route信息。之后,則是判斷route信息是否為空,如果不為空則返回被選擇演示(presentation)設(shè)備。值得一提的是,該方法只對(duì) route信息類型為ROUTE_TYPE_LIVE_VIDEO有效。

接下來(lái),只要將該Display對(duì)象作為自己重構(gòu)的演示(Presentation)類構(gòu)造函數(shù)參數(shù)傳入,這樣自己重構(gòu)的演示就會(huì)出現(xiàn)在第二個(gè)顯示設(shè)備上。

[java] view plaincopy

mPresentation = new DemoPresentation(this, presentationDisplay);

...

try {

mPresentation.show();

} catch (WindowManager.InvalidDisplayException ex) {

Log.w(TAG, Couldn't show presentation! Display was removed in

+ the meantime., ex);

mPresentation = null;

}

}

...

[java] view plaincopy

private final static class DemoPresentation extends Presentation {

...

public DemoPresentation(Context context, Display display) {

super(context, display);

}

...

}

為了進(jìn)一步優(yōu)化附加顯示設(shè)備自定義演示UI的顯示效果,你可以在



關(guān)鍵詞:

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉