简体   繁体   中英

How can i make my Android application connect to a particular single wifi before you can have access to some pages using Kotlin

So i'm working on an Android application that should use WiFi to determine if a user was within a certain building and allow them to check-in....

Is it possible to only allow users to checkin once a particular Wifi network is detected instead? I would like to do this because we are in a building where I will like users of the app to access only one of the establment's WiFi, via its ssid before they can checkin/signin on the app...

Any thoughts on how to achieve this on kotlin please? I have tried to implement this though but not working:

    Private fun conWifi(context: Context){
    val wifiManager: WifiManager = context.applicationcontext.getSystemService(Context.WIFI_SERVICE) as WifiManager
    val wifiInfo: WifiInfo! = wifiManager.conectionInfo

   if (wifiInfo.ssid.equals("SamsungWifi")){

           // some codes like show another page

       }

       else{

          // Toast...
       }

    }

Then I called it on:

enter.setonClickListener() {it: View!

     conWifi(applicationContext)

}

Please don't be offended I typed with a phone, please someone should help me and format, thank you.

According to the doc :

If the SSID can be decoded as UTF-8, it will be returned surrounded by double quotation marks. Otherwise, it is returned as a string of hex digits. The SSID may be WifiManager#UNKNOWN_SSID , if there is no network currently connected or if the caller has insufficient permissions to access the SSID.

Prior to Build.VERSION_CODES.JELLY_BEAN_MR1 , this method always returned the SSID with no quotes around it.

Maybe you want to check the double quotation marks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM