WIFI可以被编程关闭 [英] Can WIFI be turned off programatically
本文介绍了WIFI可以被编程关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何WIFI开启/关闭编程和做植根或者需要这种系统的应用程序。谢谢
How can wifi be turned off/on programatically and do is rooted or system app required for this. Thanks
推荐答案
权限是必需的。
我只是写这个程序的切换无线网络连接。
I just wrote this app that toggles Wifi.
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stackoverflow.q5766518"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="3" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission
android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission
android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity
android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle Wifi" />
</LinearLayout>
主要活动
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button myButton = (Button) findViewById(R.id.my_button);
myButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
final WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(!wifi.isWifiEnabled());
}
});
}
这篇关于WIFI可以被编程关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文