简体   繁体   English

在您可以使用 Kotlin 访问某些页面之前,如何让我的 Android 应用程序连接到特定的单个 wifi

[英]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....所以我正在开发一个 Android 应用程序,该应用程序应该使用 WiFi 来确定用户是否在某个建筑物内并允许他们签到......

Is it possible to only allow users to checkin once a particular Wifi network is detected instead?是否可以仅在检测到特定 Wifi 网络后才允许用户签入? 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...我想这样做是因为我们在一栋建筑物中,我希望该应用程序的用户在他们可以在应用程序上签入/登录之前,通过其 ssid 仅访问该建筑物的 WiFi 之一...

Any thoughts on how to achieve this on kotlin please?关于如何在 kotlin 上实现这一点的任何想法? 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.如果 SSID 可以解码为 UTF-8,则返回用双引号括起来。 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. SSID 可能是WifiManager#UNKNOWN_SSID ,如果当前没有连接网络或者调用者没有足够的权限访问 SSID。

Prior to Build.VERSION_CODES.JELLY_BEAN_MR1 , this method always returned the SSID with no quotes around it.Build.VERSION_CODES.JELLY_BEAN_MR1之前,此方法始终返回不带引号的 SSID。

Maybe you want to check the double quotation marks.也许你想检查双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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