简体   繁体   English

通过USB配置Android WIFI

[英]configure Android WIFI over USB

I have an Android device that has a WIFI adapter but no screen and no input devices. 我有一个具有WIFI适配器但没有屏幕和输入设备的Android设备。 I want to use it as a silent server in my local network that runs / offers some services and will eventually be configurable via the internet. 我想将其用作运行/提供某些服务的本地网络中的静默服务器,并且最终可以通过互联网进行配置。 The service app will be pre-installed and launch upon boot. 该服务应用将被预安装并在启动时启动。 The problem is the initial configuration (mainly join the local WIFI network). 问题是初始配置(主要是加入本地WIFI网络)。

My idea is: Develop a Java GUI app that is used for the initial setup via USB. 我的想法是:开发一个Java GUI应用程序,用于通过USB进行初始设置。

Let's assume I get the desktop app to find and communicate with the Android service via the ADK (I will be happy to share here once I succeed). 假设我获得了桌面应用程序,以通过ADK查找Android服务并与之通信(成功后我将很乐意在这里分享)。 That way I will be able to use my screen & keyboard to configure it. 这样,我将能够使用屏幕和键盘对其进行配置。 Now the problem is: 现在的问题是:

How can I (on the Android device) obtain a list of WIFI netorks that the Android device finds and how can I tell it to connect to a selected network (with a provided password)? 如何(在Android设备上)获取Android设备找到的WIFI网络列表,以及如何告诉它连接到选定的网络(使用提供的密码)?

Is there maybe a better way to achieve what I am trying to? 是否有更好的方法可以实现我想要的目标?

The WifiManager class should be helpful: WifiManager类应该会有所帮助:

This class provides the primary API for managing all aspects of Wi-Fi connectivity. 此类提供了用于管理Wi-Fi连接所有方面的主要API。 Get an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE). 通过调用Context.getSystemService(Context.WIFI_SERVICE)获取此类的实例。 It deals with several categories of items: 它涉及以下几类项目:

  • The list of configured networks. 已配置网络的列表。 The list can be viewed and updated, and attributes of individual entries can be modified. 可以查看和更新​​该列表,并且可以修改单个条目的属性。
  • The currently active Wi-Fi network, if any. 当前活动的Wi-Fi网络(如果有)。 Connectivity can be established or torn down, and dynamic information about the state of the network can be queried. 可以建立连接或断开连接,并可以查询有关网络状态的动态信息。
  • Results of access point scans, containing enough information to make decisions about what access point to connect to. 接入点扫描的结果,其中包含足够的信息来决定要连接到哪个接入点。
  • It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state. 它定义了在Wi-Fi状态发生任何变化时广播的各种Intent操作的名称。

This is the API to use when performing Wi-Fi specific operations. 这是执行Wi-Fi特定操作时要使用的API。 To perform operations that pertain to network connectivity at an abstract level, use ConnectivityManager. 要以抽象级别执行与网络连接有关的操作,请使用ConnectivityManager。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM