机器人 - 广东话移除无线网络Programatically-在类型WifiManager方法removeNetwork(int)的不适用的参数(字符串) [英] Android - Cant Remove Wifi Network Programatically- The method removeNetwork(int) in the type WifiManager is not applicable for the arguments (String)

查看:962
本文介绍了机器人 - 广东话移除无线网络Programatically-在类型WifiManager方法removeNetwork(int)的不适用的参数(字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以编程方式删除我的wifi网络 - 但我似乎无法得到它删除/忘记了当前所连接的WiFi连接。这应该是pretty的简单的任务 - 所以我不知道到底是什么,我做错了

我用下面的计算器后作为一个例子:

<一个href="http://stackoverflow.com/questions/11134383/how-to-forget-a-wireless-network-in-android-programmatically">How忘了在Android的编程无线网络?

 公共类KillTimer函数扩展了活动{

     @覆盖
   公共无效的onCreate(包savedInstanceState){
       super.onCreate(savedInstanceState);
       的setContentView(R.layout.killtimer);
       WifiManager wifiManager =(WifiManager)getApplicationContext()getSystemService(Context.WIFI_SERVICE)。
       wifiManager.getConnectionInfo()。getSSID()
       。wifiManager.getConnectionInfo()getNetoworkId();
       wifiManager.removeNetwork(wifiConfig.networkId);
       wifiManager.saveConfiguration();

   }}
 

解决方案

removeNetwork()只需要整型参数。该 networkSSID 是一个字符串值。这就是原因的错误。我看到你正在使用的SSID是一个字符串。你必须给网络ID是整数。您可以尝试 getConnectionInfo()。getSSID()和你的SSID相比较,如果它们是相同的,那么你可以尝试让 getConnectionInfo()。getNetoworkId( )这应该给所连接的网络的网络ID,你可以用它来removeNetwork。

试试这个:

 公共类KillTimer函数扩展了活动{
       @覆盖
       公共无效的onCreate(包savedInstanceState){
           super.onCreate(savedInstanceState);
           的setContentView(R.layout.killtimer);
           WifiManager wifiManager =(WifiManager)getApplicationContext()getSystemService(Context.WIFI_SERVICE)。
           INT networkId = wifiManager.getConnectionInfo()getNetworkId()。
           wifiManager.removeNetwork(networkId);
           wifiManager.saveConfiguration();
       }}
 

I'm attempting to remove my wifi network programatically - however I cannot seem to get it to remove/forget the currently connected wifi connection. This should be a pretty simple task - so I'm not sure exactly what I'm doing wrong.

I'm using the following StackOverflow post as an example:

How to forget a wireless network in android programmatically?

     public class KillTimer extends Activity {

     @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.killtimer);
       WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
       wifiManager.getConnectionInfo().getSSID()
       wifiManager.getConnectionInfo().getNetoworkId();
       wifiManager.removeNetwork(wifiConfig.networkId);
       wifiManager.saveConfiguration();

   }}

解决方案

removeNetwork() takes only integer parameters. The networkSSID is a string value. That's the cause for the error. I see that you are using SSID which is a string. You have to give the network id which is integer. You can try getConnectionInfo().getSSID() and compare with your ssid, if they are same then you can try getting getConnectionInfo().getNetoworkId() which should give the connected network's network id, which you can use to removeNetwork.

Try this:

public class KillTimer extends Activity {
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.killtimer);
           WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
           int networkId = wifiManager.getConnectionInfo().getNetworkId();
           wifiManager.removeNetwork(networkId);
           wifiManager.saveConfiguration();
       }}

这篇关于机器人 - 广东话移除无线网络Programatically-在类型WifiManager方法removeNetwork(int)的不适用的参数(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆