以编程方式设置 Android IP、DNS、GATEWAY 设置
如何以编程方式从 android java ie 设置 wifi ip 地址、dns 地址、网关,我没有找到任何能够存储这些值的方法。
How do I set wifi ip address, dns address, gateway from android java i.e programmatically, I didn't find any method which has the capability to store the values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
下面的代码也可以做到这一点:
the follow code can also do that:
您可以通过编程方式更改系统设置。
首先,您需要在“AndroidManifest.xml”中请求“WRITE_SETTINGS”权限:
然后您需要使用以下代码实际更改设置:
可以通过相同的方法访问当前设置,但使用“getString”而不是“putString” '。
有关设置选项的信息,请访问此处的参考:
Settings.System | Android 开发者
You can change system settings programatically.
First you need to request the 'WRITE_SETTINGS' permission in your 'AndroidManifest.xml':
Then you need to actually change the setting using the following code:
The current settings can be accessed via the same method but use 'getString' instead of 'putString'.
For information about the settings option visit the reference here:
Settings.System | Android Developers
您无法通过应用程序执行此操作。
您希望手机上的应用程序随意更改手机设置吗?
You can't do this from an application.
Would you like applications on your phone to change phone's settings at will?
不确定它是否有帮助,但可以在无线设置中为特定接入点手动设置备用 ip、网关、dns 等。是否可以自动执行此操作或使用意图是另一个问题?
我刚刚看到这可能会有所帮助
如何使用 Android 从我的应用程序调用 Wi-Fi 设置屏幕
Not sure it will help but it's possible to manually set an alternative ip,gateway, dns etc for a particular access point in the Wireless settings. Whether you can do this automatically or using an intent is another question?
I just saw this which might be helpful
How can i call Wi-Fi settings screen from my application using Android
android.provider.Settings.System.putString 现已弃用
这是新方法
https://developer.android.com/reference/android/net/wifi/ Wifi管理器
我也不知道如何使用这个新方法,如果有人知道请也学学我
android.provider.Settings.System.putString is deprecated now
this is the new method
https://developer.android.com/reference/android/net/wifi/WifiManager
also i don't know how to use this new method, if someone knows that please learn it to me too