Reputation: 337
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.
Upvotes: 0
Views: 176
Reputation: 905
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.
Upvotes: 2