當前位置: 首頁>>代碼示例>>Java>>正文


Java WifiManager.isWifiEnabled方法代碼示例

本文整理匯總了Java中android.net.wifi.WifiManager.isWifiEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.isWifiEnabled方法的具體用法?Java WifiManager.isWifiEnabled怎麽用?Java WifiManager.isWifiEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.isWifiEnabled方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onReceive

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    WifiManager wifiMgr = (WifiManager) context.getApplicationContext()
            .getSystemService(Service.WIFI_SERVICE);
    if (wifiMgr.isWifiEnabled()) {
        context.startService(new Intent(context, DeskDroidService.class));
    } else {
        context.stopService(new Intent(context, DeskDroidService.class));
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:11,代碼來源:WifiReceiver.java

示例2: getWifiBSSID

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * Get the BSSID of the currently-connected WiFi AP
 * @param context a Context instance
 * @return the BSSID of WiFi, or null if the device is not connected
 */
// @RequiresPermission(value = Manifest.permission.ACCESS_WIFI_STATE)
public static String getWifiBSSID(Context context) {
    WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null || !wifiManager.isWifiEnabled()) return null;
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo == null || wifiInfo.getNetworkId() == -1) return null;
    return wifiInfo.getBSSID();
}
 
開發者ID:PrivacyStreams,項目名稱:PrivacyStreams,代碼行數:14,代碼來源:DeviceUtils.java

示例3: setWifiEnabled

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 打開或關閉wifi
 * <p>需添加權限 {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打開<br>{@code false}: 關閉
 */
public static void setWifiEnabled(boolean enabled) {
    @SuppressLint("WifiManagerLeak")
    WifiManager wifiManager = (WifiManager) Utils.getContext().getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
        if (!wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(true);
        }
    } else {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
    }
}
 
開發者ID:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:20,代碼來源:NetworkUtils.java

示例4: startServer

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
protected void startServer() {
        WifiManager wifiMgr = (WifiManager) getApplicationContext()
                .getSystemService(Service.WIFI_SERVICE);
        if (wifiMgr.isWifiEnabled()) {
            // Deprecated. Does not support ipv6. *shrug* :)
            String ipAddress = Formatter.formatIpAddress(wifiMgr.getConnectionInfo()
                    .getIpAddress());

            URI baseUri = UriBuilder.fromUri("http://" + ipAddress)
                    .port(49152)
                    .build();
            ResourceConfig config = new ResourceConfig(SseFeature.class)
                    .register(JacksonFeature.class);
            config.registerInstances(new SecureFilter(this));
            config.registerInstances(new DeskDroidResource(this));
//            server = JettyHttpContainerFactory.createServer(baseUri, config);
            server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
        }
    }
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:20,代碼來源:DeskDroidService.java

示例5: setWifiEnabled

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 打開或關閉wifi
 * <p>需添加權限 {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打開<br>{@code false}: 關閉
 */
public static void setWifiEnabled(boolean enabled) {
    WifiManager wifiManager = (WifiManager) Utils.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
        if (!wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(true);
        }
    } else {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
    }
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:19,代碼來源:NetworkUtils.java

示例6: disableWifi

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
private void disableWifi() {
    WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    mPreviousWifiMode = wifiManager.isWifiEnabled();
    if(mPreviousWifiMode){
        Log.d(TAG, "Disabling Wi-Fi");
        wifiChanged = true;
        wifiManager.setWifiEnabled(false);
    }
}
 
開發者ID:swapyx,項目名稱:Channelize,代碼行數:11,代碼來源:TimerFragment.java

示例7: isWifiConnected

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * Check whether WiFi is connected
 * @param context a Context instance
 * @return true if Wifi is connected
 */
// @RequiresPermission(value = Manifest.permission.ACCESS_WIFI_STATE)
public static boolean isWifiConnected(Context context) {
    WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null || !wifiManager.isWifiEnabled()) return false;
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo == null || wifiInfo.getNetworkId() == -1) return false;
    return wifiInfo.getSupplicantState() == SupplicantState.ASSOCIATED;
}
 
開發者ID:PrivacyStreams,項目名稱:PrivacyStreams,代碼行數:14,代碼來源:DeviceUtils.java

示例8: getLocalIpAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getLocalIpAddress(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService("connectivity");
    NetworkInfo wifi = connMgr.getNetworkInfo(1);
    NetworkInfo mobile = connMgr.getNetworkInfo(0);
    if (wifi.isAvailable()) {
        WifiManager wifimanage = (WifiManager) context.getSystemService("wifi");
        wifimanage.isWifiEnabled();
        int i = wifimanage.getConnectionInfo().getIpAddress();
        return (i & 255) + "." + ((i >> 8) & 255) + "." + ((i >> 16) & 255) + "." + ((i >> 24) & 255);
    }
    if (mobile.isAvailable()) {
        try {
            Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                Enumeration<InetAddress> enumIpAddr = ((NetworkInterface) en.nextElement()).getInetAddresses();
                while (enumIpAddr.hasMoreElements()) {
                    InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        return inetAddress.getHostAddress().toString();
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:29,代碼來源:LetvUtil.java

示例9: doInBackground

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... params) {

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\"";
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

    WifiManager wifiManager = (WifiManager) getBaseContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.addNetwork(conf);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
        wifiManager.startScan();
    }

    int netId = wifiManager.addNetwork(conf);
    wifiManager.disconnect();
    wifiManager.enableNetwork(netId, true);
    wifiManager.reconnect();

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), "Joined to " + networkSSID, Toast.LENGTH_SHORT).show();
            System.out.println("SUCCESS ");
        }
    });
    return null;
}
 
開發者ID:yuvaraj119,項目名稱:WifiChatSharing,代碼行數:29,代碼來源:MainActivity.java

示例10: isWiFiAvailable

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static boolean isWiFiAvailable(Context context) {
    WifiManager wifi = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    if (wifi.isWifiEnabled()) {
        return true;
    }
    else return false;
}
 
開發者ID:uncleashi,項目名稱:find-client-android,代碼行數:8,代碼來源:Utils.java

示例11: setWifiEnabled

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 打開或關閉wifi
 * <p>需添加權限 {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打開<br>{@code false}: 關閉
 */
public static void setWifiEnabled(final boolean enabled) {
    @SuppressLint("WifiManagerLeak")
    WifiManager wifiManager = (WifiManager) Utils.getContext().getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
        if (!wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(true);
        }
    } else {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
    }
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:20,代碼來源:NetworkUtils.java

示例12: onRequestPermissionsResult

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == 0x12345) {
        for (int grantResult : grantResults) {
            if (grantResult != PackageManager.PERMISSION_GRANTED) {
                return;
            }
        }
        WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        boolean wasEnabled = myWifiManager.isWifiEnabled();
        if (!wasEnabled)
            myWifiManager.setWifiEnabled(true);
        if (myWifiManager.isWifiEnabled()) {
            if (myWifiManager.startScan()) {
                // List available APs
                Log.d("pras", "this inside scan");
                List<ScanResult> scans = myWifiManager.getScanResults();
                Log.d("pras", "" + (scans == null));
                Log.d("pras", "" + scans.isEmpty());
                if (scans != null && !scans.isEmpty()) {
                    for (ScanResult scan : scans) {
                        int level = WifiManager.calculateSignalLevel(scan.level, 20);
                        //Other code
                        Log.d("wifi", level + "this");
                    }
                } else {
                    Log.d("pras", "this inside else");
                }
            }
        }

    }

}
 
開發者ID:PrasannaNatarajan,項目名稱:Interrobang,代碼行數:35,代碼來源:MainActivity.java

示例13: getWifiBssid

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public String getWifiBssid(Context context) {
    try {
        WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
        if (wifiManager.isWifiEnabled()) {
            return wifiManager.getConnectionInfo().getBSSID();
        }
    } catch (Throwable th) {
    }
    return "";
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:11,代碼來源:DeviceInfo.java

示例14: setWifiEnabled

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 打開或關閉wifi
 * <p>需添加權限 {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打開<br>{@code false}: 關閉
 */
public static void setWifiEnabled(boolean enabled) {
    WifiManager wifiManager = (WifiManager) ToolCache.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
        if (!wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(true);
        }
    } else {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
    }
}
 
開發者ID:StickyTolt,項目名稱:ForeverLibrary,代碼行數:19,代碼來源:NetworkUtils.java

示例15: WifiStrength

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public List<Map.Entry<String, Double>> WifiStrength(){
        WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        boolean wasEnabled = myWifiManager.isWifiEnabled();
        if (!wasEnabled)
            myWifiManager.setWifiEnabled(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Log.d("pras","inside permission");
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 0x12345);
        }

        if (myWifiManager.isWifiEnabled()) {
            if (myWifiManager.startScan()) {
                // List available APs
                Log.d("pras", "inside scan");
                List<ScanResult> scans = myWifiManager.getScanResults();
                Log.d("pras", "" + (scans == null));
                Log.d("pras", "" + scans.isEmpty());

                //int topThree = 3;
                if (scans != null && !scans.isEmpty()) {
                    int i=0;
                    for (ScanResult scan : scans) {
                        Double level = (double)scan.level;
                        Log.d("frequency",scan.frequency + "");
                        //Other code
                        Log.d("pras", scan.SSID + " : " + scan.level);
//                        if(topThree!=0)

//                        Log.d("pras",scan.SSID);


                        wifiDetails.put(scan.BSSID,level);
                    }
                } else {
                    Log.d("pras", "inside else");
                }
            }
        }


        Set<Map.Entry<String, Double>> set = wifiDetails.entrySet();
        List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(set);
        Collections.sort( list, new Comparator<Map.Entry<String, Double>>()
        {
            public int compare( Map.Entry<String, Double> o1, Map.Entry<String, Double> o2 )
            {
                return (o2.getValue()).compareTo( o1.getValue() );
            }
        } );
        for(int tt = 0; tt<5; tt++)
            toastText+= list.get(tt).getKey()+ " : " + list.get(tt).getValue()   + "\n";
        for(Map.Entry<String, Double> entry:list){
            Log.d("Pras",entry.getKey()+" ==== "+entry.getValue());
        }

        return list;
    }
 
開發者ID:PrasannaNatarajan,項目名稱:Interrobang,代碼行數:59,代碼來源:MainActivity.java


注:本文中的android.net.wifi.WifiManager.isWifiEnabled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。