Android Question BroadcastReceiver for checking WiFi connectivity

Discussion in 'Android Questions' started by Harish Kumar Arya, Apr 12, 2015.

  1. Harish Kumar Arya

    Harish Kumar Arya Member Licensed User

    I would like to register a broadcast receiver for checking wifi connection in my app (within main activity). I came across a sample of java implementation of the same but having hard time transforming it to B4A. Can someone please help me out with this:

    Manifest XML:

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

    JAVA code

    this.registerReceiver(this.mConnReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {

    NetworkInfo currentNetworkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

    if (currentNetworkInfo.isConnected()) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();

    Toast.makeText(getApplicationContext(), "Broadcast Connected:" + wifiInfo.getSSID(), Toast.LENGTH_LONG).show();
    } else {
    Toast.makeText(getApplicationContext(), "Broadcast Not Connected", Toast.LENGTH_LONG).show();
    }
    }
    };
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You should use PhoneEvents from the Phone library.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice