android.net.wifi.WifiInfo Java Examples

The following examples show how to use android.net.wifi.WifiInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MacAddressUtils.java    From CacheEmulatorChecker with Apache License 2.0 6 votes vote down vote up
public static String getConnectedWifiMacAddress(Application context) {
    String connectedWifiMacAddress = null;
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> wifiList;

    if (wifiManager != null) {
        wifiList = wifiManager.getScanResults();
        WifiInfo info = wifiManager.getConnectionInfo();
        if (wifiList != null && info != null) {
            for (int i = 0; i < wifiList.size(); i++) {
                ScanResult result = wifiList.get(i);
                if (!TextUtils.isEmpty(info.getBSSID()) && info.getBSSID().equals(result.BSSID)) {
                    connectedWifiMacAddress = result.BSSID;
                }
            }
        }
    }
    return connectedWifiMacAddress;
}
 
Example #2
Source File: SignalInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
/**
 * wifi
 *
 * @param mContext
 * @return
 */
private static void getDetailsWifiInfo(Context mContext, SignalBean signalBean) {
    try {
        WifiInfo mWifiInfo = getWifiInfo(mContext);
        int ip = mWifiInfo.getIpAddress();
        String strIp = "" + (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + ((ip >> 24) & 0xFF);
        signalBean.setBssid(mWifiInfo.getBSSID());
        signalBean.setSsid(mWifiInfo.getSSID().replace("\"", ""));
        signalBean.setnIpAddress(strIp);
        signalBean.setMacAddress(getMac(mContext));
        signalBean.setNetworkId(mWifiInfo.getNetworkId());
        signalBean.setLinkSpeed(mWifiInfo.getLinkSpeed() + "Mbps");
        int rssi = mWifiInfo.getRssi();
        signalBean.setRssi(rssi);
        signalBean.setLevel(calculateSignalLevel(rssi));
        isWifiProxy(mContext, signalBean);
        signalBean.setSupplicantState(mWifiInfo.getSupplicantState().name());
        signalBean.setnIpAddressIpv6(getNetIP());
    } catch (Exception e) {
        Log.i(TAG, e.toString());
    }

}
 
Example #3
Source File: Utils.java    From RPiCameraViewer with MIT License 6 votes vote down vote up
public static String getNetworkName()
{
	String ssid = "";
	WifiManager manager = (WifiManager)App.getContext().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)
			{
				ssid = wifiInfo.getSSID();
				if (ssid == null) ssid = "";
				ssid = ssid.replaceAll("^\"|\"$", "");
				if (ssid.equals("<unknown ssid>"))
				{
					ssid = App.getStr(R.string.unknown_network);
				}
			}
		}
	}
	return ssid;
}
 
Example #4
Source File: WifiBaseActivity.java    From android-wifi-activity with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
/**
 * Start to connect to a specific wifi network
 */
private void connectToSpecificNetwork() {
    final WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    WifiInfo wifiInfo = wifi.getConnectionInfo();
    if (networkInfo.isConnected() && wifiInfo.getSSID().replace("\"", "").equals(getWifiSSID())) {
        return;
    }
    else {
        wifi.disconnect();
    }
    progressDialog = ProgressDialog.show(this, getString(R.string.connecting), String.format(getString(R.string.connecting_to_wifi), getWifiSSID()));
    taskHandler = worker.schedule(new TimeoutTask(), getSecondsTimeout(), TimeUnit.SECONDS);
    scanReceiver = new ScanReceiver();
    registerReceiver(scanReceiver
            , new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    wifi.startScan();
}
 
Example #5
Source File: DeviceInfo.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
public static int getWifiRssi(Context context) {
    int asu = 85;
    try {
        final NetworkInfo network = ((ConnectivityManager) context.getApplicationContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();
        if (network != null && network.isAvailable() && network.isConnected()) {
            final int type = network.getType();
            if (type == ConnectivityManager.TYPE_WIFI) {
                final WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);

                final WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                if (wifiInfo != null) {
                    asu = wifiInfo.getRssi();
                }
            }
        }
    } catch (Exception e) {
        Log.e("getWifiRssi", "" + e.getMessage(), e);
    }
    return asu;
}
 
Example #6
Source File: JoH.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static String getWifiSSID() {
    try {
        final WifiManager wifi_manager = (WifiManager) xdrip.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        if (wifi_manager.isWifiEnabled()) {
            final WifiInfo wifiInfo = wifi_manager.getConnectionInfo();
            if (wifiInfo != null) {
                final NetworkInfo.DetailedState wifi_state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
                if (wifi_state == NetworkInfo.DetailedState.CONNECTED
                        || wifi_state == NetworkInfo.DetailedState.OBTAINING_IPADDR
                        || wifi_state == NetworkInfo.DetailedState.CAPTIVE_PORTAL_CHECK) {
                    String ssid = wifiInfo.getSSID();
                    if (ssid.equals("<unknown ssid>")) return null; // WifiSsid.NONE;
                    if (ssid.charAt(0) == '"') ssid = ssid.substring(1);
                    if (ssid.charAt(ssid.length() - 1) == '"')
                        ssid = ssid.substring(0, ssid.length() - 1);
                    return ssid;
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception in getWifiSSID: " + e);
    }
    return null;
}
 
Example #7
Source File: NetworkUtil.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
/**
 * result[0] is self ip,result[1] is host ip,result[2] is isWifiEnable,true or false.
 */
public static ArrayList<String> getWifiHostAndSelfIP(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    String isWifiEnable;
    if (!wifiManager.isWifiEnabled()) {
        isWifiEnable = "false";
    } else
        isWifiEnable = "true";
    ArrayList<String> result = new ArrayList<>();
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String IPAddress = intToIp(wifiInfo.getIpAddress());
    result.add(IPAddress);

    DhcpInfo dhcpinfo = wifiManager.getDhcpInfo();
    String serverAddress = intToIp(dhcpinfo.serverAddress);
    result.add(serverAddress);

    result.add(isWifiEnable);
    return result;
}
 
Example #8
Source File: ProvisioningValuesLoader.java    From android-NfcProvisioning with Apache License 2.0 6 votes vote down vote up
private void loadSystemValues(HashMap<String, String> values) {
    Context context = getContext();
    //noinspection deprecation
    putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
            "com.example.android.deviceowner");
    if (Build.VERSION.SDK_INT >= 23) {
        putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
                "com.example.android.deviceowner/.DeviceOwnerReceiver");
    }
    putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_LOCALE,
            CompatUtils.getPrimaryLocale(context.getResources().getConfiguration()).toString());
    putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE,
            TimeZone.getDefault().getID());
    if (!values.containsKey(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID)) {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Activity.WIFI_SERVICE);
        WifiInfo info = wifiManager.getConnectionInfo();
        if (info.getNetworkId() != -1) { // Connected to network
            values.put(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID,
                    trimSsid(info.getSSID()));
        }
    }
}
 
Example #9
Source File: DownloadService.java    From rcloneExplorer with MIT License 6 votes vote down vote up
private boolean checkWifiOnAndConnected() {
    WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

    if (wifiMgr == null) {
        return false;
    }

    if (wifiMgr.isWifiEnabled()) { // Wi-Fi adapter is ON

        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();

        return wifiInfo.getNetworkId() != -1;
    }
    else {
        return false; // Wi-Fi adapter is OFF
    }
}
 
Example #10
Source File: WifiBase.java    From android-wifi-activity with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
/**
 * Start to connect to a specific wifi network
 */
private void connectToSpecificNetwork() {
    final WifiManager wifi = (WifiManager) getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    WifiInfo wifiInfo = wifi.getConnectionInfo();
    if (networkInfo.isConnected() && wifiInfo.getSSID().replace("\"", "").equals(getWifiSSID())) {
        return;
    }
    else {
        wifi.disconnect();
    }
    progressDialog = ProgressDialog.show(getContext(), getContext().getString(R.string.connecting), String.format(getContext().getString(R.string.connecting_to_wifi), getWifiSSID()));
    taskHandler = worker.schedule(new TimeoutTask(), getSecondsTimeout(), TimeUnit.SECONDS);
    scanReceiver = new ScanReceiver();
    getContext().registerReceiver(scanReceiver
            , new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    wifi.startScan();
}
 
Example #11
Source File: SetupFlowTest.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void mockDeviceDiscoveryResult(String ssid) {
    ScanResult scanResult = mock(ScanResult.class);
    scanResult.SSID = ssid;
    scanResult.capabilities = "WEP";
    //mock wifi wrapper to return fake photon device in scan results
    List<ScanResult> scanResultList = new ArrayList<>();
    scanResultList.add(scanResult);
    when(wifiFacade.getScanResults()).thenReturn(scanResultList);
    //create fake wifi info object for fake photon device
    WifiInfo wifiInfo = mock(WifiInfo.class);
    when(wifiInfo.getSSID()).thenReturn(ssid);
    when(wifiInfo.getNetworkId()).thenReturn(5);
    //mock wifi wrapper to return fake photon device as "connected" network
    when(wifiFacade.getCurrentlyConnectedSSID()).thenReturn(SSID.from(ssid));
    when(wifiFacade.getConnectionInfo()).thenReturn(wifiInfo);
    //mock device discovery process worker to do nothing (would throw exception),
    //doing nothing would mean successful connection to ap
    try {
        doNothing().when(discoverProcessWorker).doTheThing();
    } catch (SetupStepException e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: Utils.java    From HJMirror with MIT License 6 votes vote down vote up
/**
 * wifi获取ip
 */
public String getIp(Application context) {
    try {
        //获取wifi服务
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wifiManager == null) {
            return null;
        }
        //判断wifi是否开启
        if (!wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(true);
        }
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ipAddress = wifiInfo.getIpAddress();
        String ip = intToIp(ipAddress);
        return ip;
    } catch (Exception e) {

    }
    return null;
}
 
Example #13
Source File: DeviceUtil.java    From SimpleProject with MIT License 6 votes vote down vote up
/**
 * 获取手机的Mac地址
 * @param context
 * @return
 */
@SuppressLint("MissingPermission")
public static String getMacAddress(Context context) {
	String macAddress = "";
	WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	if (wifiManager != null) {
		try {
			WifiInfo wifiInfo = wifiManager.getConnectionInfo();
			macAddress = wifiInfo != null ? wifiInfo.getMacAddress() : "";
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
	}

	return macAddress;
}
 
Example #14
Source File: ThetaDeviceDetectionFromAccessPoint.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    String action = intent.getAction();
    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        if (wifiInfo != null) {
            onNetworkChanged(wifiInfo);
        }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        switch (state) {
            case WifiManager.WIFI_STATE_DISABLED:
                onWiFiDisabled();
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                onWiFiEnabled();
                break;
            default:
                break;
        }
    }
}
 
Example #15
Source File: MainActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkWifiState() {

        // Check connection state
        WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        if (wifiMgr.isWifiEnabled()) { // WiFi adapter is ON
            WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
            if (wifiInfo.getNetworkId() == -1) {
                return false; // Not connected to an access-Point
            }
            // Connected to an Access Point
            return true;
        } else {
            return false; // WiFi adapter is OFF
        }
    }
 
Example #16
Source File: ConnectionHelper.java    From an2linuxclient with GNU General Public License v3.0 5 votes vote down vote up
public static boolean checkIfSsidIsAllowed(String ssidWhitelist, Context c){
    if (ssidWhitelist == null){
        return true;
    }
    WifiManager wifiManager = (WifiManager) c.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    String connectedToSsid = info.getSSID();
    for (String ssid : ssidWhitelist.split("(?<!\\\\),")){
        if (connectedToSsid.equals("\"" + ssid.trim().replace("\\,", ",") + "\"")){
            return true;
        }
    }
    return false;
}
 
Example #17
Source File: IpUtil.java    From BaseProject with MIT License 5 votes vote down vote up
/**
 * 获取IP地址(网络为Wifi)
 */
@RequiresPermission(allOf = {Manifest.permission.CHANGE_WIFI_STATE,
                             Manifest.permission.ACCESS_WIFI_STATE})
public static String getWifiIp(@NonNull Context context) {
    // 获取wifi服务
    WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    // 判断wifi是否开启
    if (null != wifiManager && !wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ipAddress = wifiInfo.getIpAddress();
        return intToIp(ipAddress);
    }
    return null;
}
 
Example #18
Source File: DeviceUtils.java    From ToolsFinal with Apache License 2.0 5 votes vote down vote up
/**
 * 获取MAC地址
 * @param context
 * @return
 */
public static String getMac(Context context) {
    WifiManager wifi = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String mac = info.getMacAddress();
    if ( StringUtils.isEmpty(mac) ) {
        mac = "";
    }
    return mac;
}
 
Example #19
Source File: ESPDevice.java    From esp-idf-provisioning-android with Apache License 2.0 5 votes vote down vote up
@RequiresPermission(allOf = {Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.ACCESS_WIFI_STATE})
private String fetchWiFiSSID() {

    String ssid = null;
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {

        ssid = wifiInfo.getSSID();
        ssid = ssid.replace("\"", "");
    }
    Log.e(TAG, "Returning ssid : " + ssid);
    return ssid;
}
 
Example #20
Source File: Util.java    From Connect-SDK-Android-Core with Apache License 2.0 5 votes vote down vote up
public static InetAddress getIpAddress(Context context) throws UnknownHostException {
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();

    if (ip == 0) {
        return null;
    }
    else {
        byte[] ipAddress = convertIpAddress(ip);
        return InetAddress.getByAddress(ipAddress);
    }
}
 
Example #21
Source File: RemoteKeyboardService.java    From remotekeyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Update the message in the notification area
 * 
 * @param remote
 *          the remote host we are connected to or null if not connected.
 */
protected void updateNotification(InetAddress remote) {
	String title = getResources().getString(R.string.notification_title);
	String content = null;
	if (remote == null) {
		// FIXME: This is anything but pretty! Apparently someone at Google thinks
		// that WLAN is ipv4 only.
		WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
		WifiInfo wifiInfo = wifiManager.getConnectionInfo();
		int addr = wifiInfo.getIpAddress();
		String ip = (addr & 0xFF) + "." + ((addr >> 8) & 0xFF) + "."
				+ ((addr >> 16) & 0xFF) + "." + ((addr >> 24) & 0xFF);
		content = getResources()
				.getString(R.string.notification_waiting, "" + ip);
	}
	else {
		content = getResources().getString(R.string.notification_peer,
				remote.getHostName());
	}

	NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
	builder
			.setContentText(content)
			.setContentTitle(title)
			.setOngoing(true)
			.setContentIntent(
					PendingIntent.getActivity(this, 0, new Intent(this,
							MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT))
			.setSmallIcon(R.drawable.ic_stat_service);
	NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	notificationManager.notify(NOTIFICATION, builder.build());
}
 
Example #22
Source File: JacksonActivity.java    From My-MVP with Apache License 2.0 5 votes vote down vote up
@Nullable
    private String getWifiSSID() {

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


        if (wifiManager != null && wifiManager.isWifiEnabled()) {
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            if (wifiInfo != null) {
                NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
                if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
                    return wifiInfo.getSSID();
                }
            }
        }

//        Optional.ofNullable(wifiManager).ifPresent((WifiManager wifiManager1) -> {
//            if (wifiManager1.isWifiEnabled()) {
//                WifiInfo wifiInfo = wifiManager1.getConnectionInfo();
//                Optional.ofNullable(wifiInfo).ifPresent((Consumer<WifiInfo>) (WifiInfo wifiInfo1) -> {
//                    NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf(wifiInfo1.getSupplicantState());
//                    if (detailedState == NetworkInfo.DetailedState.CONNECTED || detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
//
//                        return wifiInfo1.getSSID();
//                    }
//                });
//            }
//
//
//        });
        return null;
    }
 
Example #23
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
private void getFrequency(Result poResult) {
    WifiInfo info = moWiFi.getConnectionInfo();
    int frequency = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        frequency = info.getFrequency();
    }
    poResult.success(frequency);
}
 
Example #24
Source File: MobileUtil.java    From zone-sdk with MIT License 5 votes vote down vote up
/**
 * 获取 MAC 地址
 * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
 */
public static String getMacAddress(Context context) {
    //wifi mac地址
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String mac = info.getMacAddress();
    LogZSDK.INSTANCE.i(" MAC:" + mac);
    return mac;
}
 
Example #25
Source File: WifiDelegate.java    From wifi with MIT License 5 votes vote down vote up
private void launchIP() {
    NetworkInfo info = ((ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            try {
                for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                    NetworkInterface intf = en.nextElement();
                    for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                        InetAddress inetAddress = enumIpAddr.nextElement();
                        if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                            result.success(inetAddress.getHostAddress());
                            clearMethodCallAndResult();
                        }
                    }
                }
            } catch (SocketException e) {
                e.printStackTrace();
            }
        } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());
            result.success(ipAddress);
            clearMethodCallAndResult();
        }
    } else {
        finishWithError("unavailable", "ip not available.");
    }
}
 
Example #26
Source File: PickServerFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private void updateWifiInfo() {
    WifiInfo info = getConnectionInfo();
    if (info != null) {
        mPreferenceWiFi.setChecked(true);
        String ssid = info.getSSID();
        String template = getString(R.string.summary_wifi_connected);
        Object[] objects = {
            ssid != null ? ssid : ""
        };
        mPreferenceWiFi.setSummary(MessageFormat.format(template, objects));
    } else {
        mPreferenceWiFi.setChecked(false);
        mPreferenceWiFi.setSummary(R.string.summary_wifi_disconnected);
    }
}
 
Example #27
Source File: LetvUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static String getMacAddress() {
    if (TextUtils.isEmpty(sMacAddress)) {
        WifiInfo wifiInfo = ((WifiManager) BaseApplication.getInstance().getSystemService("wifi")).getConnectionInfo();
        if (wifiInfo == null) {
            return "";
        }
        sMacAddress = BaseTypeUtils.ensureStringValidate(wifiInfo.getMacAddress());
        LogInfo.log(TAG, "get macaddress:" + sMacAddress);
        return sMacAddress;
    }
    LogInfo.log(TAG, "sMacAddress:" + sMacAddress);
    return sMacAddress;
}
 
Example #28
Source File: Salut.java    From Salut with MIT License 5 votes vote down vote up
public Salut(SalutDataReceiver dataReceiver, SalutServiceData salutServiceData, SalutCallback deviceNotSupported) {
    WifiManager wifiMan = (WifiManager) dataReceiver.context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMan.getConnectionInfo();

    this.dataReceiver = dataReceiver;
    this.deviceNotSupported = deviceNotSupported;
    this.TTP = salutServiceData.serviceData.get("SERVICE_NAME") + TTP;

    thisDevice = new SalutDevice();
    thisDevice.serviceName = salutServiceData.serviceData.get("SERVICE_NAME");
    thisDevice.readableName = salutServiceData.serviceData.get("INSTANCE_NAME");
    thisDevice.instanceName = "" + wifiInfo.getMacAddress().hashCode();
    thisDevice.macAddress = wifiInfo.getMacAddress();
    thisDevice.TTP = thisDevice.serviceName + TTP;
    thisDevice.servicePort = Integer.valueOf(salutServiceData.serviceData.get("SERVICE_PORT"));
    thisDevice.txtRecord = salutServiceData.serviceData;

    foundDevices = new ArrayList<>();

    intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    manager = (WifiP2pManager) dataReceiver.context.getSystemService(Context.WIFI_P2P_SERVICE);
    channel = manager.initialize(dataReceiver.context, dataReceiver.context.getMainLooper(), new WifiP2pManager.ChannelListener() {
        @Override
        public void onChannelDisconnected() {
            Log.d(TAG, "Attempting to reinitialize channel.");
            channel = manager.initialize(Salut.this.dataReceiver.context, Salut.this.dataReceiver.context.getMainLooper(), this);
        }
    });

    receiver = new SalutBroadcastReceiver(this, manager, channel);
}
 
Example #29
Source File: DeviceInfoManager.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * 获取Mac地址
 * 
 * @param context
 * @return
 */
public static String getMacAddress(Context context)
{
	WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	WifiInfo info = wifi.getConnectionInfo();

	return info.getMacAddress();
}
 
Example #30
Source File: WifiUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前连接的 Wifi SSID
 * @return Wifi SSID
 */
@SuppressLint("MissingPermission")
public static String getSSID() {
    try {
        // 获取当前连接的 Wifi
        WifiInfo wifiInfo = AppUtils.getWifiManager().getConnectionInfo();
        // 获取 Wifi SSID
        return formatSSID(wifiInfo.getSSID(), false);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getSSID");
    }
    return null;
}