You are on page 1of 1

AndroidManifest.xml and activity_main.

xml

No changes

MainActvivity.java
package com.example.q1;

import androidx.appcompat.app.AppCompatActivity;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IntentFilter filter = new
IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
registerReceiver(wifi,filter);
IntentFilter filter2 = new
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(airplaneMode,filter2);
IntentFilter filter3 = new
IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(bluetooth,filter3);

}
private final BroadcastReceiver wifi = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
{
Toast.makeText(getApplicationContext(), "WIFI state has been
changed", Toast.LENGTH_SHORT).show();
}
}
};
private final BroadcastReceiver airplaneMode = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_AIRPLANE_MODE_CHANGED))
{
Toast.makeText(getApplicationContext(), "Airplane mode state has
been changed", Toast.LENGTH_SHORT).show();
}
}
};
private final BroadcastReceiver bluetooth = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED))
{
Toast.makeText(getApplicationContext(), "Bluetooth mode state has
been changed", Toast.LENGTH_SHORT).show();
}
}
};
}

You might also like