Ravi Kumar
Ravi Kumar

Reputation: 341

Android - Show Notification with text for the connected WiFi devices

If the mobile connecting to open network(router), the system displays notification which takes to browser for sign in.

Similarly Is it possible to show notification with custom text which open an browser with the intent url, when a device connects to wifi(Android wifi hotspot) ?

Note:

the devices connecting to the wifi does not have my app. The notification need to send by the android device which is hosting the wifi hotspot

Upvotes: 0

Views: 1601

Answers (2)

Ratna deep verma
Ratna deep verma

Reputation: 141

1) You can use BroadcastReciever "android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED" to detect client connection.

In your AndroidManifest:

<receiver
    android:name=".WiFiConnectionReciever"
    android:enabled="true"
    android:exported="true" >
    <intent-filter>
        <action android:name="android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED" />
    </intent-filter>
</receiver>

And in Activity:

IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction("android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED");
rcv = new WiFiConnectionReciever();
registerReceiver(rcv,mIntentFilter);

2) You can also get the list of connected devices to HOTSPOT

public void getConnectedClientList() {
    int clientcount = 0;
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
                String mac = splitted[3];
                System.out.println("Mac : Outside If "+ mac );
                if (mac.matches("..:..:..:..:..:..")) {
                    clientcount++;
                    System.out.println("Mac : "+ mac + " IP Address : "+splitted[0] );
                    System.out.println("Client_count  " + clientcount + " MAC_ADDRESS  "+ mac);
                    Toast.makeText(
                            getApplicationContext(),
                            "Client_count  " + clientcount + "   MAC_ADDRESS  "
                                    + mac, Toast.LENGTH_SHORT).show();

                }
            }

    } catch(Exception e) {
    }
}

Upvotes: 1

Dungnbhut
Dungnbhut

Reputation: 176

Now you can create broad listener network change and call one intent Check INTENT internet connection

Upvotes: 1

Related Questions