This video shows the steps to create an Android App which can be used to control the state of your Wifi between ON and OFF. The concept shown in this video is very simple. However, the use cases to control the state of the wifi could be many which has been briefly discussed in this video. Some of the use cases could be to control the wifi remotely by sending the command over channels such as SMS, firebase database update, etc. It can also be controlled at a pre-set time using some kind of timer or alarm clock concept.
We hope you like this video. For any query, suggestions or appreciations we will be glad to hear from you at: programmerworld1990@gmail.com
Source Code:
package com.example.mywificontrolapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;public class MainActivity extends AppCompatActivity {
private WifiManager wifiManager;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
}public void WifiOnButton(View view){
wifiManager.setWifiEnabled(true);
}public void WifiOffButton(View view){
wifiManager.setWifiEnabled(false);
}
}
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.mywificontrolapp”><uses-permission android:name=”android.permission.CHANGE_WIFI_STATE”/>
<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application></manifest>
How to control the wifi remotely by sending the command over channels such as SMS, firebase database update, etc. It can also be controlled at a pre-set time using some kind of timer or alarm clock concept ?
You can read the SMS and based on the conditions met trigger the Wifi ON/OFF command as below:
wifiManager.setWifiEnabled(true);
SMS reading use case is discussed in the below pages:
https://programmerworld.co/android/how-to-access-sms-or-read-last-sms-in-your-phone-using-your-app-android-studio-java-code/
https://programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/
Cheers
Programmer World
–