当前位置: 首页>>代码示例>>Java>>正文


Java WifiInfo.getSSID方法代码示例

本文整理汇总了Java中android.net.wifi.WifiInfo.getSSID方法的典型用法代码示例。如果您正苦于以下问题:Java WifiInfo.getSSID方法的具体用法?Java WifiInfo.getSSID怎么用?Java WifiInfo.getSSID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.wifi.WifiInfo的用法示例。


在下文中一共展示了WifiInfo.getSSID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getWifiSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/**
 * Gets the SSID of the currently associated WiFi access point if there is one. Otherwise,
 * returns empty string.
 */
@CalledByNative
public static String getWifiSSID(Context context) {
    if (context == null) {
        return "";
    }
    final Intent intent = context.registerReceiver(
            null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
    if (intent != null) {
        final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
        if (wifiInfo != null) {
            final String ssid = wifiInfo.getSSID();
            if (ssid != null) {
                return ssid;
            }
        }
    }
    return "";
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:23,代码来源:AndroidNetworkLibrary.java

示例2: getWifiName

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public String getWifiName(Context context) {
    WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (manager.isWifiEnabled()) {
        WifiInfo wifiInfo = manager.getConnectionInfo();
        if (wifiInfo != null) {
            NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
            if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
                return wifiInfo.getSSID();
            }
        }
    }
    return null;
}
 
开发者ID:BloomBooks,项目名称:BloomReader,代码行数:14,代码来源:GetFromWiFiActivity.java

示例3: getConnectedSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/**
 * This method retrieves the SSID for the currently connected network
 *
 *    @param    callbackContext        A Cordova callback context
 *    @return    true if SSID found, false if not.
*/
private boolean getConnectedSSID(CallbackContext callbackContext){
    if(!wifiManager.isWifiEnabled()){
        callbackContext.error("Wifi is disabled");
        return false;
    }

    WifiInfo info = wifiManager.getConnectionInfo();

    if(info == null){
        callbackContext.error("Unable to read wifi info");
        return false;
    }

    String ssid = info.getSSID();
    if(ssid.isEmpty()) {
        ssid = info.getBSSID();
    }
    if(ssid.isEmpty()){
        callbackContext.error("SSID is empty");
        return false;
    }

    callbackContext.success(ssid);
    return true;
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:32,代码来源:WifiWizard.java

示例4: getCurrentSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getCurrentSSID(Context context) throws Exception {
    try {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    } catch (Exception e) {
        throw new Exception("目前WIFI連線名稱讀取時發生錯誤");
    }

}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:12,代码来源:WifiUtility.java

示例5: checkConnectedToDesiredWifi

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/** Detect you are connected to a specific network. */
private boolean checkConnectedToDesiredWifi() {
    boolean connected = false;

    WifiManager wifiManager =
            (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

    WifiInfo wifi = wifiManager.getConnectionInfo();
    if (wifi != null) {
        // get current router Mac address
        String ssid = wifi.getSSID();
        if(mSSID != null){
            connected = mSSID.equals(ssid);
        }
        Log.d(mTAG, "IP: " + NetworkUtils.getIPV4Address(mContext));
    }

    return connected;
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:20,代码来源:WifiSta.java

示例6: onReceive

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
@TargetApi(23)
@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences preferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
    String homeNetwork = preferences.getString("ssid", "HackZurich2017");

    String action = intent.getAction();
    if (action.equals("android.net.conn.CONNECTIVITY_CHANGE")) {
        WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if(wifiMgr.isWifiEnabled()){
            WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
            String name = wifiInfo.getSSID();
            Container container = Container.instance();
            container.addObserver(new PositionService(context));
            if(name.equals(homeNetwork)){
                container.stopTimer();
                DBHelper helper = new DBHelper(context, DBHelper.DB_NAME, null, DBHelper.currentVersion);
                helper.insertRoute(container.getRoute());
                // reset Route
                container.setRoute(new Route());
            }else{
                container.startTimer();
            }
        }
    }
}
 
开发者ID:BernhardWebstudio,项目名称:ShadowTravelor,代码行数:27,代码来源:NetworkBroadcast.java

示例7: getWifiSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
@ReactMethod
public void getWifiSSID(Callback callback){
    String SSID;
    Context context = this.getReactApplicationContext();
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if(networkInfo != null && networkInfo.isConnected()){
        WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        SSID = wifiInfo.getSSID();
        if(SSID.startsWith("\"") && SSID.endsWith("\""))
            SSID = SSID.substring(1, SSID.length()-1);
        callback.invoke(null, SSID);
    }
    else{
        callback.invoke("Error: unable to retrieve SSID.", null);
    }
}
 
开发者ID:pengyanb,项目名称:react-native-pybwifiparam,代码行数:19,代码来源:PybWifiParamModule.java

示例8: getConnectWifiSsid

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/**
 * 获取当前连接wifi的名称
 *
 * @return
 */
public static String getConnectWifiSsid(Context context) {
    if (isWifiConnected(context)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:NetworkUtils.java

示例9: getWifiSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
String getWifiSSID() {
  final Intent intent = context.registerReceiver(
      null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
  if (intent != null) {
    final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
    if (wifiInfo != null) {
      final String ssid = wifiInfo.getSSID();
      if (ssid != null) {
        return ssid;
      }
    }
  }
  return "";
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:15,代码来源:NetworkMonitorAutoDetect.java

示例10: getWifiName

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public  static String getWifiName(Context context) {
    if(context == null)
        return null;
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiMgr.getConnectionInfo();
    String wifiId = info != null ? info.getSSID() : null;
    if(!TextUtils.isEmpty(wifiId)) {
        wifiId = wifiId.replace("\"","");
    }
    return wifiId;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:12,代码来源:WifiUtil.java

示例11: updateWifiInfo

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
private void updateWifiInfo() {
    WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();

    wifiSsid = wifiInfo.getSSID();
    wifiBssid = wifiInfo.getBSSID();
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:8,代码来源:InformationFieldsFactory.java

示例12: getCurrentWifiSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getCurrentWifiSSID(Context context) {
    String ssid = "";
    if (context != null) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        ssid = wifiInfo.getSSID();
        if (ssid.substring(0, 1).equals("\"") && ssid.substring(ssid.length() - 1).equals("\"")) {
            ssid = ssid.substring(1, ssid.length() - 1);
        }
    }
    return ssid;
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:13,代码来源:NetworkUtils.java

示例13: b

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
private static String b(Context context) {
    WifiInfo connectionInfo = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo();
    if (connectionInfo != null) {
        return connectionInfo.getSSID();
    }
    return "-1";
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:c.java

示例14: getWifiSSID

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getWifiSSID(Context context)
{
    Context applicationContext = context.getApplicationContext();
    WifiManager wifiManager = (WifiManager) applicationContext.getSystemService (applicationContext.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();

    if(info == null)
    {
        return "";
    }

    return info.getSSID();
}
 
开发者ID:wrld3d,项目名称:android-api,代码行数:14,代码来源:WifiSSIDQuerier.java

示例15: onReceive

import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
@Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
            NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            if (info.getState().equals(NetworkInfo.State.CONNECTED)) {

                WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                String wifiName = wifiInfo.getSSID();   //获取的是带引号的如"Young"
                if(TextUtils.isEmpty(wifiName)) return;

                wifiName = wifiName.split("\"")[1]; //去引号
//                Log.e(tag, "连接到WIFI " + wifiName);
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                for (int i = 0; i < aims.length;i++){
                    if(wifiName.equalsIgnoreCase(aims[i])){
//                        Log.e(tag, "登陆~ " + wifiName);
                        Toast.makeText(context.getApplicationContext(), "登陆 "+aims[i], Toast.LENGTH_SHORT).show();

                        SharedPreferences sp = context.getSharedPreferences(MainActivity.PREFERENCES_NAME, Activity.MODE_PRIVATE);
                        String str_acc = sp.getString("account", "");
                        String str_psw = sp.getString("password", "");
                        if(TextUtils.isEmpty(str_acc)||TextUtils.isEmpty(str_psw)){
                            Toast.makeText(context.getApplicationContext(), "账号或密码为空", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        DrcomAdmin drcomAdmin = DrcomAdmin.getInstance();
                        drcomAdmin.initAccountInfo(str_acc, str_psw);
                        drcomAdmin.login();
                        break;
                    }
                }
                // 当前WIFI名称

            }
        }
    }
 
开发者ID:WeGdufe,项目名称:Gdufe-Drcom-Solution,代码行数:43,代码来源:NetWorkChangeReceiver.java


注:本文中的android.net.wifi.WifiInfo.getSSID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。