0

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

Ravi Kumar
  • 339
  • 2
  • 11
  • 24

2 Answers2

1

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

Community
  • 1
  • 1
Dungnbhut
  • 176
  • 5
  • This going to work if my app is there in the wifi connecting device. If my app is not there, then this fails. – Ravi Kumar May 10 '17 at 05:19
1

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) {
    }
}
Ratna deep verma
  • 141
  • 1
  • 11
  • My app is not in the connected wifi device, then what would be the case to send notification from the device which is hosting the wifi ? – Ravi Kumar May 10 '17 at 05:11
  • You can check the edited answer . You can also go through [Android Wifi Hotspot Manager Class](https://www.whitebyte.info/android/android-wifi-hotspot-manager-class) this have sample code to scan /proc/net/arp and ping each known client to detect livelihood. – Ratna deep verma May 10 '17 at 05:40
  • Thanks for your response. Your code helps to fetch the wifi connected device ipAddress. But could i be able to show notification with intent url in the connected wifi devices ? – Ravi Kumar May 10 '17 at 08:52
  • You can't send notification to connected wifi devices because if they do not have your application then you can not push notification to those devices. – Ratna deep verma May 10 '17 at 10:38