Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Android app code: Start stop Wi-Fi with Java code

 

With Java you can directly Wi-Fi into an Android app or turn off.

To do this, you must have associated with previously the permissions the app and then via a WiFi Manager on or off - switch

 

Right start: WifiManager.setWifiEnabled (true/false)

 

 

 

Video tutorial

 

 

Java code to start and stop the Wi-Fi function

Start and stop of the Wi-Fi connection. The status is performed by the WifiManger.setWifiEnabled(Status)

public void bntStart_Wifi_by_Manger_onClick(View view) {
//---< btnStart_Wifi_onClick() >--
WifiManager wifi;
wifi=(WifiManager)getSystemService(Context.
WIFI_SERVICE);

wifi.setWifiEnabled(
true);//Turn Wifi on
//---</ btnStart_Wifi_onClick() >--
}

public void bntStop_Wifi_by_Manger_onClick(View view) {
//---< bntStop_Wifi_by_Manger_onClick() >--
WifiManager wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(
false);//Turn Wifi off
//---</ bntStop_Wifi_by_Manger_onClick() >--
}
 

 

 

The app at all must perform this action directly in the code, the app must have access permission.

These must be inserted in the AndroidManifest.xml

It is required the ACCESS_WIFI_STATE and CHANGE_WIFI_STATE

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.rue25.demo_2016_07_29_ask_wifi">

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

 

 

In the application in Android Studio

 

Open form of Wi-Fi

To manually enter a statement for the user, you can open form about an intent the WiFi

To do this, you need to create a new intent with the parameter: settings. ACTION_WIFI_SETTINGS

As soon as it is opened as activity, appears the form to the control or manual modification.

public void btnStart_Wifi_onClick(View view) {
//---< btnStart_Wifi_onClick() >--

Intent intent_Start_Wifi=new Intent(Settings.ACTION_WIFI_SETTINGS);

startActivity(intent_Start_Wifi);
//---</ btnStart_Wifi_onClick() >--
}

 

 

 

 

 

MainActivity with 3 buttons: the first button is to the start of the form.


 
 

Mobile
»
App settings as app preferences save and read
»
Add Android settings to an app project
»
Android code: Lookup a contact by the phone number
»
Android code: Add contact person, email, telephone with batch operations
»
Android Studio: Add contact using Android intent
»
Android code: Automatically dial a phone number
»
Android app code: Start stop Wi-Fi with Java code
»
Android app code: App to turn on WiFi by Intent
»
Android: Macro Coding with Intent and StartActivity
»
Android code: Android read contacts and store it in a ListView

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de