編輯:Android開發實例
Android 2.2 開始增加了WiFi Hotspot,可將Android設備作為無線熱點、向其他WiFi設備共享網絡連接,參考 Sharing your mobile data connection
前面,我將 Realtek 8192cu 驅動移植到 Android 2.2。Realtek 8192cu 驅動包中也包含了一個 hostapd 的實現以及Android SoftapController實現,通過以下步驟,可以在Android上實現SoftAP
1、在init.rc中增加hostapd服務
service hostapd /system/bin/hostapd_wps /data/misc/wifi/hostapd.conf
group wifi inet
disabled
oneshot
2、移植Realtek的hostapd實現
將驅動包中的external\hostapd-0.6.9_rtl 復制到Android 的external/ 目錄下。需要修改 external/hostapd-0.6.9_rtl/hostapd/Android.mk,在文件接近末尾處,增刪如下所示的幾行
OBJS_c = hostapd/hostapd_cli.c src/common/wpa_ctrl.c src/utils/os_$(CONFIG_OS).c
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd_cli
#LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS_c))
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)
OBJS_c = hostapd/hostapd_wps.c
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd_wps
#LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS_c))
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd
#LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_SHARED_LIBRARIES += $(LIBS)
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS))
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)
local_target_dir := $(TARGET_OUT)/etc/wifi
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd.conf
#LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(local_target_dir)
LOCAL_SRC_FILES := hostapd$(HOSTAPD_VER)/hostapd/hostapd.conf.android
include $(BUILD_PREBUILT)
OBJS_c = src/common/wpa_ctrl.c src/utils/os_$(CONFIG_OS).c
include $(CLEAR_VARS)
LOCAL_MODULE = libhostapd_client
LOCAL_PRELINK_MODULE := false
#LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS = $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS_c))
LOCAL_C_INCLUDES = $(INCLUDES)
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_COPY_HEADERS_TO := libhostapd_client
LOCAL_COPY_HEADERS := hostapd$(HOSTAPD_VER)/src/common/wpa_ctrl.h
include $(BUILD_SHARED_LIBRARY
3、移植Realtek的SoftapController實現
將Realtek驅動包中system\netd\ 目錄下的Android.mk、SoftapController_realtek.cpp 2個文件復制/覆蓋到 Android 源碼 system/netd/ 目錄下
修改 Android 源碼 frameworks/base/core/res/res/values/config.xml 文件,找到下面2個字符串數組,分別增加如下幾個item:
<!-- List of regexpressions describing the interface (if any) that represent tetherable
Wifi interfaces. If the device doesn't want to support tethering over Wifi this
should be empty. An example would be "softap.*" -->
<string-array translatable="false" name="config_tether_wifi_regexs">
<item>"wlap0"</item>
</string-array>
<!-- Regex array of allowable upstream ifaces for tethering - for example if you want
tethering on a new interface called "foo2" add <item>"foo\\d"</item> to the array -->
<string-array translatable="false" name="config_tether_upstream_regexs">
<item>"ppp\\d"</item>
<item>"eth\\d"</item>
<item>"wlan\\d"</item>
</string-array>
Android運行後,通過Settings->Wireless & Networks->Portable hotspot 啟用“Portable Wi-Fi hotspot”,並可通過 Portable Wi-Fi hotspot settings->Configure Wi-Fi hotspot 設置SSID、安全性等。我這邊看到支持Open、WPA2 PSK 2種安全選項
Hotspot啟動後,其它WiFi設備就可以連接上來
android.net.wifi.WifiManager 類有幾個關於SoftAP的隱藏接口,應用程序可以通過反射來調用:
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個
本文實例講述了Android編程之SurfaceView學習示例。分享給大家供大家參考,具體如下: SurfaceView是View的子類,使用的方式與任何Vie
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用
酷酷的外表已經具備了,那就開始讓我們真正把它的功能給實現起來吧,外強中干,花拳繡腿可不行哦,我們需要真正的本領,需要一顆自強不息的心哦,常常想想自己的夢想什麼,這