本文整理匯總了Java中android.net.wifi.WifiManager.reconnect方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.reconnect方法的具體用法?Java WifiManager.reconnect怎麽用?Java WifiManager.reconnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.reconnect方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connectToKnownWifi
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static void connectToKnownWifi(Context context, String ssid) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
}
}
}
示例2: connectToConfiguredNetwork
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
private static boolean connectToConfiguredNetwork(@NonNull WifiManager wifiManager, @Nullable WifiConfiguration config, boolean reassociate) {
if (config == null)
return false;
if (Build.VERSION.SDK_INT >= 23)
return disableAllButOne(wifiManager, config) && (reassociate ? wifiManager.reassociate() : wifiManager.reconnect());
int oldPri = config.priority;
// Make it the highest priority.
int newPri = getMaxPriority(wifiManager) + 1;
if (newPri > MAX_PRIORITY) {
newPri = shiftPriorityAndSave(wifiManager);
config = ConfigSecurities.getWifiConfiguration(wifiManager, config);
if (config == null)
return false;
}
// Set highest priority to this configured network
config.priority = newPri;
int networkId = wifiManager.updateNetwork(config);
if (networkId == -1)
return false;
// Do not disable others
if (!wifiManager.enableNetwork(networkId, false)) {
config.priority = oldPri;
return false;
}
if (!wifiManager.saveConfiguration()) {
config.priority = oldPri;
return false;
}
// We have to retrieve the WifiConfiguration after save.
config = ConfigSecurities.getWifiConfiguration(wifiManager, config);
return config != null && disableAllButOne(wifiManager, config) && (reassociate ? wifiManager.reassociate() : wifiManager.reconnect());
}
示例3: doInBackground
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... params) {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
WifiManager wifiManager = (WifiManager) getBaseContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
wifiManager.startScan();
}
int netId = wifiManager.addNetwork(conf);
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Joined to " + networkSSID, Toast.LENGTH_SHORT).show();
System.out.println("SUCCESS ");
}
});
return null;
}
示例4: onCreate
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();
}
}
}
示例5: onReceive
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION .equals(action)) {
SupplicantState state = intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
if (SupplicantState.isValidState(state)
&& state == SupplicantState.COMPLETED) {
mIsConnected = checkConnectedToDesiredWifi();
if(mCallback != null){
if(mIsConnected){
mCallback.onSuccess();
}
else{
mCallback.onFailed();
}
}
}
else if(SupplicantState.isValidState(state)
&& state == SupplicantState.DISCONNECTED){
Log.d(mTAG, "Wifi STA is disconnected");
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
wifiManager.reconnect();
}
}
}
示例6: connect
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public void connect(String ssid, String pwd, WiFiStaConnectCallback callback){
if(callback == null){
return;
}
mCallback = callback;
mSSID = ssid;
mPWD = pwd;
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration config = new WifiConfiguration();
config.SSID = "\"" + mSSID + "\"";
if(pwd.equals("")){
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
else{
config.preSharedKey = "\"" + mPWD + "\"";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
}
config.status = WifiConfiguration.Status.ENABLED;
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
if(!wifiManager.isWifiEnabled()){
wifiManager.setWifiEnabled(true);
}
wifiManager.startScan();
int networkId = wifiManager.addNetwork(config);
wifiManager.disconnect();
wifiManager.enableNetwork(networkId, true);
wifiManager.reconnect();
}
示例7: connectWifi
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@ProtoMethod(description = "Connect to mContext given Wifi network with mContext given 'wpa', 'wep', 'open' type and mContext password", example = "")
@ProtoMethodParam(params = {"ssidName", "type", "password"})
public void connectWifi(String networkSSID, String type, String networkPass) {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String
// should contain ssid in quotes
if (type.equals("wep")) {
// wep
conf.wepKeys[0] = "\"" + networkPass + "\"";
conf.wepTxKeyIndex = 0;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
} else if (type.equals("wpa")) {
// wpa
conf.preSharedKey = "\"" + networkPass + "\"";
} else if (type.equals("open")) {
// open
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
WifiManager wifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
}
示例8: connectToNtutcc
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static boolean connectToNtutcc(Context context) {
try {
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + NTUTCC_SSID + "\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + NTUTCC_SSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
return true;
}
}
} catch (Exception e) {
}
return false;
}