java wifimanager_Java WifiManager.disableNetwork方法代码示例

这篇博客展示了如何在Java中利用WifiManager的disableNetwork方法来断开指定网络连接,并在之后进行重新连接。通过获取SSID并检查特定条件,该代码确保了特定WiFi网络的断开与重新连接操作。
摘要由CSDN通过智能技术生成

import android.net.wifi.WifiManager; //导入方法依赖的package包/类

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

setContentView(R.layout.activity_bind_device_error);

AndroidBug54971Workaround.assistActivity(findViewById(android.R.id.content));

int currentapiVersion = android.os.Build.VERSION.SDK_INT;

if (currentapiVersion >= 20) {

getWindow().setStatusBarColor(getResources().getColor(R.color.bar_color));

}

llBack = (LinearLayout) findViewById(R.id.ll_back);

// llBack.setOnClickListener(new View.OnClickListener() {

// @Override

// public void onClick(View v) {

// finish();

// }

// });

TextView btnSure = (TextView) findViewById(R.id.tvEditSure);

btnSure.setVisibility(View.INVISIBLE);

llBack.setVisibility(View.INVISIBLE);

TextView tvTitle = (TextView) findViewById(R.id.tvTitle);

tvTitle.setText(R.string.find_devices);

type = getIntent().getIntExtra("type", 0);

//断开网络重新连接

if (type == 1) {

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

String ssid = wifiManager.getConnectionInfo().getSSID();

if (ssid.contains("Photon-") && ssid.length() >= 11) {

wifiManager.disableNetwork(wifiManager.getConnectionInfo().getNetworkId());

//连接到最后一次的网络上

wifiManager.reconnect();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值