开发者

Enabled using coding for use wireless network

I am new to android i stuck for using coding enable location and sectury in that use wireless network enabled so pl开发者_运维问答ease tell mi how it's possible

thanks priya naral


From what I gathered, you want to programmatically turn on Wi-Fi.

If so, first you need to add these to your AndroidManifest.xml:

<application>
    .
    .
    .
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
</application>

Then you have the ability to use WifiManager, so your code would look something like the following, where this is your application Context:

WifiManager manager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

if(!manager.isWifiEnabled()){
    manager.setWifiEnabled(true);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜