Wait for a specific wifi?

Asked

Viewed 43 times

1

I created the following test, searching the name of the WIFI and the MACADDRESS of who sends me this WIFI.

I would like to be "listening" if there is a specific WIFI, so that when finding it, do something.

How to do this?

Below is the code I’m using:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Solicita as permissões
        String[] permissoes = new String[]{
                Manifest.permission.ACCESS_WIFI_STATE,
                Manifest.permission.CHANGE_WIFI_STATE,
                Manifest.permission.INTERNET,
                Manifest.permission.ACCESS_NETWORK_STATE,
        };
        PermissionUtils.validate(this, 0, permissoes);

        //Getting the connection info
        WifiManager wifiManager = (WifiManager) getContext().getApplicationContext().getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        //Access point's MAC address
        String bssid = wifiInfo.getBSSID();
        String ssid = wifiInfo.getSSID();

        TextView wifi = (TextView) findViewById(R.id.wifi);
        TextView mac = (TextView) findViewById(R.id.mac);

        if (bssid != null) {
            mac.setText(bssid);
        }

        if (ssid != null && ssid.equals("specific wifi")) {
            doSomething();
            wifi.setText(wifiInfo.getSSID());
        }
    }

    private void doSomething() {
        //TODO something
    }

    protected Context getContext(){
        return this;
    }

}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.bob.getwifitest2">
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_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>
  • 1

    This is a beauty for safety. This is the most used way to play on other people’s phones. It’s all that the hacker want, a device that totally trusts in a wifi honeypot :)

  • @bigown opa, worth the tip. But the full use is not there. I just need to know when a wifi specifies appear. Thanks!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.