简体   繁体   English

移动应用开发

[英]Mobile app development

有什么办法可以开发一个只能连接学院WLAN的app,并且限制app使用移动数据和其他无线网络。

  1. Do you mean an app that can access data only through college WLAN?您是说只能通过大学 WLAN 访问数据的应用程序吗? Then yes那么是的

  2. If you mean an app that restrict user's phone from connecting to any other source of internet, then NO.如果您的意思是限制用户手机连接到任何其他互联网来源的应用程序,那么否。

The user has the highest power on deciding what he wants to do with his phone, apps requires permission from users用户拥有决定他想用手机做什么的最高权力, 应用程序需要用户的许可

If it is case 1, You can try checking whether it is using WIFI or data:如果是情况1,您可以尝试检查它是否在使用WIFI或数据:

public static String checkNetworkStatus(final Context context) {

        String networkStatus = "";

        // Get connect mangaer
        final ConnectivityManager connMgr = (ConnectivityManager)  
                context.getSystemService(Context.CONNECTIVITY_SERVICE);

        // check for wifi
        final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        // check for mobile data
        final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if( wifi.isAvailable() ) {
            networkStatus = "wifi";
        } else if( mobile.isAvailable() ) {
            networkStatus = "mobileData";
        } else {
            networkStatus = "noNetwork";
        }

        return networkStatus;

}  // end checkNetworkStatus 

Then get the wifi name, and compare that to your college wifi name:然后获取 wifi 名称,并将其与您的大学 wifi 名称进行比较:

public String getWifiName(Context context) {
    WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (manager.isWifiEnabled()) {
       WifiInfo wifiInfo = manager.getConnectionInfo();
       if (wifiInfo != null) {
          DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
          if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
              return wifiInfo.getSSID();
          }
       }
    }
    return null;
}

Happy Coding快乐编码

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

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