本文整理了Java中android.net.wifi.WifiManager.setWifiEnabled()
方法的一些代码示例,展示了WifiManager.setWifiEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.setWifiEnabled()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:setWifiEnabled
暂无
代码示例来源:origin: stackoverflow.com
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
wifiManager.setWifiEnabled(false);
代码示例来源:origin: stackoverflow.com
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(status);
代码示例来源:origin: stackoverflow.com
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false); // true or false to activate/deactivate wifi
代码示例来源:origin: stackoverflow.com
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
代码示例来源:origin: stackoverflow.com
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
代码示例来源:origin: stackoverflow.com
WifiManager wManager = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wManager.setWifiEnabled(booleanValue); //true or false
代码示例来源:origin: stackoverflow.com
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WifiManager wfm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
try {
wfm.setWifiEnabled(Boolean.parseBoolean(getIntent().getStringExtra("wifi")));
} catch (Exception e) {
}
System.exit(0);
}
}
代码示例来源:origin: 4thline/cling
public boolean enableWiFi() {
log.info("Enabling WiFi...");
try {
return wifiManager.setWifiEnabled(true);
} catch (Throwable t) {
// workaround (HTC One X, 4.0.3)
//java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider
// uri content://settings/system from pid=4691, uid=10226 requires android.permission.WRITE_SETTINGS
// at android.os.Parcel.readException(Parcel.java:1332)
// at android.os.Parcel.readException(Parcel.java:1286)
// at android.net.wifi.IWifiManager$Stub$Proxy.setWifiEnabled(IWifiManager.java:1115)
// at android.net.wifi.WifiManager.setWifiEnabled(WifiManager.java:946)
log.log(Level.WARNING, "SetWifiEnabled failed", t);
return false;
}
}
代码示例来源:origin: RobotiumTech/robotium
/**
* Sets if wifi data should be turned on or off. Requires android.permission.CHANGE_WIFI_STATE in the AndroidManifest.xml of the application under test.
*
*
* @param turnedOn true if mobile wifi is to be turned on and false if not
*/
public void setWiFiData(Boolean turnedOn){
WifiManager wifiManager = (WifiManager)instrumentation.getTargetContext().getSystemService(Context.WIFI_SERVICE);
try{
wifiManager.setWifiEnabled(turnedOn);
}catch(Exception e){
e.printStackTrace();
}
}
}
代码示例来源:origin: stackoverflow.com
wifi.setWifiEnabled(true);
代码示例来源:origin: stackoverflow.com
boolean res1 = wifiManag.setWifiEnabled(true);
int res = wifiManag.addNetwork(selectedConfig);
Log.d("WifiPreference", "add Network returned " + res );
代码示例来源:origin: robolectric/robolectric
@Test
public void getWifiState() throws Exception {
wifiManager.setWifiEnabled(true);
assertThat(wifiManager.getWifiState()).isEqualTo(WifiManager.WIFI_STATE_ENABLED);
wifiManager.setWifiEnabled(false);
assertThat(wifiManager.getWifiState()).isEqualTo(WifiManager.WIFI_STATE_DISABLED);
}
代码示例来源:origin: stackoverflow.com
boolean res1 = wifiManag.setWifiEnabled(true);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
代码示例来源:origin: robolectric/robolectric
@Test
public void setWifiEnabled_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted()
throws Exception {
shadowOf(wifiManager).setAccessWifiStatePermission(false);
try {
wifiManager.setWifiEnabled(true);
fail("SecurityException not thrown");
} catch (SecurityException e) {
// expected
}
}
代码示例来源:origin: cSploit/android
mWifiManager.setWifiEnabled(true);
mStatusText.setText(getString(R.string.wifi_activated));
代码示例来源:origin: mayubao/KuaiChuan
/**
* 关闭Wifi
*/
public void disableWifi(){
if(mWifiManager != null){
mWifiManager.setWifiEnabled(false);
}
}
代码示例来源:origin: palaima/DebugDrawer
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
wifiManager.setWifiEnabled(isChecked);
}
});
代码示例来源:origin: mayubao/KuaiChuan
/**
* 关闭wifi
*/
public void closeWifi(){
if(mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(false);
}
}
代码示例来源:origin: mayubao/KuaiChuan
/**
* 打开wifi
*/
public void openWifi(){
if(!mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(true);
}
}
代码示例来源:origin: chrisk44/Hijacker
void restore(String firm_location){
WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(wifiManager!=null) wifiManager.setWifiEnabled(false);
shell.run(busybox + " mount -o rw,remount,rw /system");
shell.run("cp " + firm_backup_file + " " + firm_location);
shell.run(busybox + " mount -o ro,remount,ro /system");
Toast.makeText(getActivity(), R.string.restored, Toast.LENGTH_SHORT).show();
if(wifiManager!=null) wifiManager.setWifiEnabled(true);
dismissAllowingStateLoss();
}
内容来源于网络,如有侵权,请联系作者删除!