简体   繁体   English

如何以编程方式连接到无线网络?

[英]How to connect to a wireless network programmatically?

I have a java application and two different wireless network connections (wifi) on my desktop. 我的桌面上有一个Java应用程序和两个不同的无线网络连接(wifi)。 This is a desktop application, not android. 这是桌面应用程序,不是android。

One method of this applicaiton works well with wifi1 , second method works well with wifi2 . 此应用程序的一种方法适用于wifi1 ,第二种方法适用于wifi2

So far in order to use different methods I have to change wifi settings on my desktop manually. 到目前为止,为了使用不同的方法,我必须手动更改桌面上的wifi设置。

Is there any way I could change wifi connection setting from the application programmatically ? 有什么办法可以通过程序从应用程序更改wifi连接设置吗?

Java is a High-Level, Platform-Independent programming language. Java是一种高级的,独立于平台的编程语言。 Network settings, and how you control them will depend on your Operating System, and to my knowledge there is no simple way to expose this in Java. 网络设置以及如何控制它们取决于您的操作系统,据我所知,没有简单的方法可以在Java中公开它。

' Luckily, some platform-dependent code mixed with Java can help you achieve the result you're after. 幸运的是,某些与平台相关的代码与Java混合可以帮助您实现所追求的结果。

  1. The Java Java

    See the Runtime.exec() method, which allows you access to the Windows Command Line or the Mac/Linux Terminal. 请参阅Runtime.exec()方法,该方法允许您访问Windows命令行或Mac / Linux终端。

  2. The Windows (Adjust for other OS'es) Windows(适用于其他操作系统)

    Now that we have access to the Command Line, we have to run the proper, platform-specific command. 现在我们可以访问命令行了,我们必须运行适当的,特定于平台的命令。 See this tutorial for Windows. 请参阅Windows的本教程

Note that it is not a good idea to modify a user's network settings (or anything else external to your application) without their consent. 请注意,未经用户同意修改用户的网络设置(或应用程序外部的任何其他内容)不是一个好主意。

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

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