Example usage for android.bluetooth BluetoothDevice getAddress

List of usage examples for android.bluetooth BluetoothDevice getAddress

Introduction

In this page you can find the example usage for android.bluetooth BluetoothDevice getAddress.

Prototype

public String getAddress() 

Source Link

Document

Returns the hardware address of this BluetoothDevice.

Usage

From source file:org.bcsphere.bluetooth.BluetoothSamAPI.java

@Override
public void getScanData(JSONArray json, CallbackContext callbackContext) {
    Log.i(TAG, "getScanData");
    JSONArray jsonDevices = new JSONArray();
    for (BluetoothDevice device : bluetoothDevices) {
        String deviceID = device.getAddress();
        JSONObject jsonDevice = new JSONObject();
        Tools.addProperty(jsonDevice, Tools.DEVICE_ID, deviceID);
        Tools.addProperty(jsonDevice, Tools.DEVICE_NAME, device.getName());
        Tools.addProperty(jsonDevice, Tools.IS_CONNECTED, bluetoothGatt.getConnectedDevices().contains(device));
        Tools.addProperty(jsonDevice, Tools.RSSI, mapRssiData.get(deviceID));
        Tools.addProperty(jsonDevice, Tools.ADVERTISEMENT_DATA,
                Tools.decodeAdvData(mapDeviceAdvData.get(deviceID)));
        jsonDevices.put(jsonDevice);/*ww w .  j a va 2s.  c  om*/
    }
    callbackContext.success(jsonDevices);
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void connectBioHarness() {
    if (bluetoothAdapter == null)
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName().startsWith("BH")) {
                if (bluetoothAddresses.contains(device.getAddress())) {
                    if (bioHarnessService != null) {
                        bioHarnessService.connectBioHarness(device.getAddress(),
                                new BioHarnessHandler(this, new int[] { 100, 1000 }));
                    }/* ww  w .ja v  a2  s . c  o  m*/
                }
            }
        }
    }
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case REQUEST_ENABLE_BT:
        if (resultCode == RESULT_OK) {
            Toast.makeText(MainActivity.this, getString(R.string.bluetooth_activated), Toast.LENGTH_LONG)
                    .show();//w  w  w  . j  av a 2  s  .c om
        }
        break;

    case PERMISSIONS_REQUEST:
        if (resultCode == RESULT_OK) {
            Toast.makeText(MainActivity.this, getString(R.string.permission_granted), Toast.LENGTH_LONG).show();
        }
        break;

    case MSG_BLUETOOTH_ADDRESS:
        if (resultCode == Activity.RESULT_OK) {
            String bluetoothAddress = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
            Log.d(TAG, "Bluetooth address: " + bluetoothAddress);

            // Check, if device is list view
            if (!getBluetoothAddresses().contains(bluetoothAddress)) {
                Log.d(TAG, "Bluetooth address of a new device");
                addBluetoothAddress(bluetoothAddress);

                bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
                BluetoothDevice device = bluetoothAdapter.getRemoteDevice(bluetoothAddress);

                String deviceName = device.getName();
                if (deviceName == null) {
                    Log.d(TAG, "Device has no device name");
                    deviceName = bluetoothAddress + "";
                }

                // Change list view
                deviceNames.add(deviceName);
                arrayAdapter.notifyDataSetChanged();

                // Check, if device is paired
                Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
                boolean paired = false;
                for (BluetoothDevice pairedDevice : pairedDevices) {
                    if (pairedDevice.getAddress().equals(bluetoothAddress)) {
                        paired = true;
                        Log.d(TAG, "Device already paired");
                    }
                }
                if (!paired) {
                    pairBluetoothDevice(device);
                }

                if (device.getName().startsWith("RN42") & shimmerImuService == null) {
                    Intent intent = new Intent(this, ShimmerImuService.class);
                    startService(intent);
                    getApplicationContext().bindService(intent, shimmerImuServiceConnection,
                            Context.BIND_AUTO_CREATE);
                    registerReceiver(shimmerImuReceiver, new IntentFilter("de.bogutzky.data_collector.app"));
                }

                if (device.getName().startsWith("BH") & bioHarnessService == null) {
                    Intent intent = new Intent(this, BioHarnessService.class);
                    startService(intent);
                    getApplicationContext().bindService(intent, bioHarnessServiceConnection,
                            Context.BIND_AUTO_CREATE);
                    registerReceiver(bioHarnessReceiver, new IntentFilter("de.bogutzky.data_collector.app"));
                }

            } else {
                Toast.makeText(this, getString(R.string.device_is_already_in_list), Toast.LENGTH_LONG).show();
            }
        }
        break;
    case REQUEST_MAIN_COMMAND_SHIMMER:
        if (resultCode == Activity.RESULT_OK) {
            int action = data.getIntExtra("action", 0);
            String bluetoothDeviceAddress = data.getStringExtra("bluetoothDeviceAddress");
            int which = data.getIntExtra("which", 0);
            if (action == 13) {
                showGraph(bluetoothDeviceAddress, REQUEST_MAIN_COMMAND_SHIMMER, which);
            }
        }
        break;
    case REQUEST_MAIN_COMMAND_BIOHARNESS:
        if (resultCode == Activity.RESULT_OK) {
            int action = data.getIntExtra("action", 0);
            String bluetoothDeviceAddress = data.getStringExtra("bluetoothDeviceAddress");
            if (action == 13) {
                showGraph(bluetoothDeviceAddress, REQUEST_MAIN_COMMAND_BIOHARNESS, -1);
            }
        }
        break;
    }
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void connectAllShimmerImus() {
    if (bluetoothAdapter == null)
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    int count = 0;
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName().contains("RN42")) {
                if (bluetoothAddresses.contains(device.getAddress())) {
                    if (shimmerImuService != null) {
                        shimmerImuService.connectShimmerImu(device.getAddress(), Integer.toString(count),
                                new ShimmerImuHandler(this, "imu-" + device.getName().toLowerCase() + ".csv",
                                        2500));
                        count++;/*from  ww  w  . j av a2  s  . co  m*/
                    }
                }
            }
        }
    }
}

From source file:com.example.RITW.Ble.BleProfileServiceReadyActivity.java

@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
    final int titleId = getLoggerProfileTitle();
    if (titleId > 0)
        //         mLogSession = Logger.newSession(getApplicationContext(), getString(titleId), device.getAddress(), name);
        mDeviceNameView.setText(mDeviceName = name);
    //   mConnectButton.setText(R.string.action_disconnect);

    // The device may not be in the range but the service will try to connect to it if it reach it
    //      Logger.v(mLogSession, "Creating service...");
    final Intent service = new Intent(this, getServiceClass());
    service.putExtra(BleProfileService.EXTRA_DEVICE_ADDRESS, device.getAddress());
    //      if (mLogSession != null)
    //         service.putExtra(BleProfileService.EXTRA_LOG_URI, mLogSession.getSessionUri());
    startService(service);// w w w  .ja  v a2 s  .co  m
    bindService(service, mServiceConnection, 0);
}

From source file:org.bcsphere.bluetooth.BluetoothSamAPI.java

@Override
public void getPairedDevices(JSONArray json, CallbackContext callbackContext) {
    Log.i(TAG, "getPairedDevices");
    if (!isInitialized(callbackContext)) {
        return;// w  ww . j a  va2 s . co m
    }
    Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
    JSONArray jsonDevices = new JSONArray();
    for (BluetoothDevice device : bondedDevices) {
        JSONObject jsonDevice = new JSONObject();
        Tools.addProperty(jsonDevice, Tools.DEVICE_ID, device.getAddress());
        Tools.addProperty(jsonDevice, Tools.DEVICE_NAME, device.getName());
        jsonDevices.put(jsonDevice);
    }
    callbackContext.success(jsonDevices);
}

From source file:org.bcsphere.bluetooth.BluetoothSamAPI.java

@Override
public void getConnectedDevices(JSONArray json, CallbackContext callbackContext) {
    Log.i(TAG, "getConnectedDevices");
    if (!isInitialized(callbackContext)) {
        return;//from www. j ava  2s .  c  o  m
    }
    @SuppressWarnings("unchecked")
    List<BluetoothDevice> bluetoothDevices = bluetoothGatt.getConnectedDevices();
    JSONArray jsonDevices = new JSONArray();
    for (BluetoothDevice device : bluetoothDevices) {
        JSONObject jsonDevice = new JSONObject();
        Tools.addProperty(jsonDevice, Tools.DEVICE_ID, device.getAddress());
        Tools.addProperty(jsonDevice, Tools.DEVICE_NAME, device.getName());
        jsonDevices.put(jsonDevice);
    }
    callbackContext.success(jsonDevices);
}

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

private void runRealObdBluetoothScan(final int obd_timeout_ms, final ObdProtocols obd_protocol) {
    if (!obdBridgeBluetooth.isBluetoothEnabled()) {
        final Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBluetooth, BLUETOOTH_REQUEST);
        return;/*from  w  w w .  j av  a2 s .  co m*/
    }
    final Set<BluetoothDevice> pairedDevicesSet = obdBridgeBluetooth.getPairedDeviceSet();

    // In case user clicks on Change Network, need to repopulate the devices list
    final ArrayList<String> deviceNames = new ArrayList<>();
    final ArrayList<String> deviceAddresses = new ArrayList<>();
    if (pairedDevicesSet != null && pairedDevicesSet.size() > 0) {
        for (BluetoothDevice device : pairedDevicesSet) {
            deviceNames.add(device.getName());
            deviceAddresses.add(device.getAddress());
        }
        final String preferredName = getPreference(SettingsFragment.BLUETOOTH_DEVICE_NAME, "obd").toLowerCase();
        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this,
                R.style.AppCompatAlertDialogStyle);
        final ArrayAdapter adapter = new ArrayAdapter(Home.this, android.R.layout.select_dialog_singlechoice,
                deviceNames.toArray(new String[deviceNames.size()]));
        int selectedDevice = -1;
        for (int i = 0; i < deviceNames.size(); i++) {
            if (deviceNames.get(i).toLowerCase().contains(preferredName)) {
                selectedDevice = i;
            }
        }
        alertDialog.setCancelable(false).setSingleChoiceItems(adapter, selectedDevice, null)
                .setTitle("Please Choose the OBDII Bluetooth Device")
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        final int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
                        final String deviceAddress = deviceAddresses.get(position);
                        final String deviceName = deviceNames.get(position);
                        startConnectingBluetoothDevice(deviceAddress, deviceName, obd_timeout_ms, obd_protocol);
                        setPreference(SettingsFragment.BLUETOOTH_DEVICE_NAME, deviceName);
                    }
                }).show();
    } else {
        Toast.makeText(getApplicationContext(),
                "Please pair with your OBDII device and restart the application!", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java

private boolean enableBluetoothConnectivity() {
    Log.d(TAG, "EnableBluetoothConnectivity");
    if (mBluetoothManager == null) {
        mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        if (mBluetoothManager == null) {
            Log.w(TAG, "EnableBluetoothConnectivity: Failed to obtain BluetoothManager");
            return false;
        }/*  w w  w. ja v a 2  s.  c o  m*/
    }

    mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (mBluetoothAdapter == null) {
        Log.w(TAG, "EnableBluetoothConnectivity: Failed to obtain BluetoothAdapter");
        return false;
    }

    mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
    if (mBluetoothLeScanner == null) {
        Log.w(TAG, "EnableBluetoothConnectivity: Failed to obtain BluetoothLeScanner");
        return false;
    }

    // The first auto-connection after boot might be missed due to starting time of the updater service.
    List<BluetoothDevice> connectedDevices = mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT);
    for (BluetoothDevice device : connectedDevices) {
        if (isTargetKeyboard(device) && !isUpdateServiceInUse()) {
            Log.d(TAG, "enableBluetoothConnectivity: Found keyboard " + device.getName() + " ["
                    + device.getAddress() + "] connected");
            obtainKeyboardInfo(device.getName(), device.getAddress());
            break;
        }
    }

    return true;
}

From source file:com.landenlabs.all_devtool.NetFragment.java

public void updateList() {
    // Time today = new Time(Time.getCurrentTimezone());
    // today.setToNow();
    // today.format(" %H:%M:%S")
    Date dt = new Date();
    m_titleTime.setText(m_timeFormat.format(dt));

    boolean expandAll = m_list.isEmpty();
    m_list.clear();//from   w w w.  j a v a 2s.c  o m

    // Swap colors
    int color = m_rowColor1;
    m_rowColor1 = m_rowColor2;
    m_rowColor2 = color;

    ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);

    try {
        String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);
        addBuild("Android ID", androidIDStr);

        try {
            AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext());
            final String adIdStr = adInfo.getId();
            final boolean isLAT = adInfo.isLimitAdTrackingEnabled();
            addBuild("Ad ID", adIdStr);
        } catch (IOException e) {
            // Unrecoverable error connecting to Google Play services (e.g.,
            // the old version of the service doesn't support getting AdvertisingId).
        } catch (GooglePlayServicesNotAvailableException e) {
            // Google Play services is not available entirely.
        }

        /*
        try {
        InstanceID instanceID = InstanceID.getInstance(getContext());
        if (instanceID != null) {
            // Requires a Google Developer project ID.
            String authorizedEntity = "<need to make this on google developer site>";
            instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            addBuild("Instance ID", instanceID.getId());
        }
        } catch (Exception ex) {
        }
        */

        ConfigurationInfo info = actMgr.getDeviceConfigurationInfo();
        addBuild("OpenGL", info.getGlEsVersion());
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    // --------------- Connection Services -------------
    try {
        ConnectivityManager connMgr = (ConnectivityManager) getActivity()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo netInfo = connMgr.getActiveNetworkInfo();
        if (netInfo != null) {
            Map<String, String> netListStr = new LinkedHashMap<String, String>();

            putIf(netListStr, "Available", "Yes", netInfo.isAvailable());
            putIf(netListStr, "Connected", "Yes", netInfo.isConnected());
            putIf(netListStr, "Connecting", "Yes", !netInfo.isConnected() && netInfo.isConnectedOrConnecting());
            putIf(netListStr, "Roaming", "Yes", netInfo.isRoaming());
            putIf(netListStr, "Extra", netInfo.getExtraInfo(), !TextUtils.isEmpty(netInfo.getExtraInfo()));
            putIf(netListStr, "WhyFailed", netInfo.getReason(), !TextUtils.isEmpty(netInfo.getReason()));
            if (Build.VERSION.SDK_INT >= 16) {
                putIf(netListStr, "Metered", "Avoid heavy use", connMgr.isActiveNetworkMetered());
            }

            netListStr.put("NetworkType", netInfo.getTypeName());
            if (connMgr.getAllNetworkInfo().length > 1) {
                netListStr.put("Available Networks:", " ");
                for (NetworkInfo netI : connMgr.getAllNetworkInfo()) {
                    if (netI.isAvailable()) {
                        netListStr.put(" " + netI.getTypeName(), netI.isAvailable() ? "Yes" : "No");
                    }
                }
            }

            if (netInfo.isConnected()) {
                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()) {
                                if (inetAddress.getHostAddress() != null) {
                                    String ipType = (inetAddress instanceof Inet4Address) ? "IPv4" : "IPv6";
                                    netListStr.put(intf.getName() + " " + ipType, inetAddress.getHostAddress());
                                }
                                // if (!TextUtils.isEmpty(inetAddress.getHostName()))
                                //     listStr.put( "HostName", inetAddress.getHostName());
                            }
                        }
                    }
                } catch (Exception ex) {
                    m_log.e("Network %s", ex.getMessage());
                }
            }

            addBuild("Network...", netListStr);
        }
    } catch (Exception ex) {
        m_log.e("Network %s", ex.getMessage());
    }

    // --------------- Telephony Services -------------
    TelephonyManager telephonyManager = (TelephonyManager) getActivity()
            .getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        Map<String, String> cellListStr = new LinkedHashMap<String, String>();
        try {
            cellListStr.put("Version", telephonyManager.getDeviceSoftwareVersion());
            cellListStr.put("Number", telephonyManager.getLine1Number());
            cellListStr.put("Service", telephonyManager.getNetworkOperatorName());
            cellListStr.put("Roaming", telephonyManager.isNetworkRoaming() ? "Yes" : "No");
            cellListStr.put("Type", getNetworkTypeName(telephonyManager.getNetworkType()));

            if (Build.VERSION.SDK_INT >= 17) {
                if (telephonyManager.getAllCellInfo() != null) {
                    for (CellInfo cellInfo : telephonyManager.getAllCellInfo()) {
                        String cellName = cellInfo.getClass().getSimpleName();
                        int level = 0;
                        if (cellInfo instanceof CellInfoCdma) {
                            level = ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel();
                        } else if (cellInfo instanceof CellInfoGsm) {
                            level = ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel();
                        } else if (cellInfo instanceof CellInfoLte) {
                            level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel();
                        } else if (cellInfo instanceof CellInfoWcdma) {
                            if (Build.VERSION.SDK_INT >= 18) {
                                level = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel();
                            }
                        }
                        cellListStr.put(cellName, "Level% " + String.valueOf(100 * level / 4));
                    }
                }
            }

            for (NeighboringCellInfo cellInfo : telephonyManager.getNeighboringCellInfo()) {
                int level = cellInfo.getRssi();
                cellListStr.put("Cell level%", String.valueOf(100 * level / 31));
            }

        } catch (Exception ex) {
            m_log.e("Cell %s", ex.getMessage());
        }

        if (!cellListStr.isEmpty()) {
            addBuild("Cell...", cellListStr);
        }
    }

    // --------------- Bluetooth Services (API18) -------------
    if (Build.VERSION.SDK_INT >= 18) {
        try {
            BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (bluetoothAdapter != null) {

                Map<String, String> btListStr = new LinkedHashMap<String, String>();

                btListStr.put("Enabled", bluetoothAdapter.isEnabled() ? "yes" : "no");
                btListStr.put("Name", bluetoothAdapter.getName());
                btListStr.put("ScanMode", String.valueOf(bluetoothAdapter.getScanMode()));
                btListStr.put("State", String.valueOf(bluetoothAdapter.getState()));
                Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
                // If there are paired devices
                if (pairedDevices.size() > 0) {
                    // Loop through paired devices
                    for (BluetoothDevice device : pairedDevices) {
                        // Add the name and address to an array adapter to show in a ListView
                        btListStr.put("Paired:" + device.getName(), device.getAddress());
                    }
                }

                BluetoothManager btMgr = (BluetoothManager) getActivity()
                        .getSystemService(Context.BLUETOOTH_SERVICE);
                if (btMgr != null) {
                    // btMgr.getAdapter().
                }
                addBuild("Bluetooth", btListStr);
            }

        } catch (Exception ex) {

        }
    }

    // --------------- Wifi Services -------------
    final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);

    if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) {

        if (mSystemBroadcastReceiver == null) {
            mSystemBroadcastReceiver = new SystemBroadcastReceiver(wifiMgr);
            getActivity().registerReceiver(mSystemBroadcastReceiver, INTENT_FILTER_SCAN_AVAILABLE);
        }

        if (ActivityCompat.checkSelfPermission(getContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(getContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            if (wifiMgr.getScanResults() == null || wifiMgr.getScanResults().size() != mLastScanSize) {
                mLastScanSize = wifiMgr.getScanResults().size();
                wifiMgr.startScan();
            }
        }

        Map<String, String> wifiListStr = new LinkedHashMap<String, String>();
        try {
            DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo();

            wifiListStr.put("DNS1", Formatter.formatIpAddress(dhcpInfo.dns1));
            wifiListStr.put("DNS2", Formatter.formatIpAddress(dhcpInfo.dns2));
            wifiListStr.put("Default Gateway", Formatter.formatIpAddress(dhcpInfo.gateway));
            wifiListStr.put("IP Address", Formatter.formatIpAddress(dhcpInfo.ipAddress));
            wifiListStr.put("Subnet Mask", Formatter.formatIpAddress(dhcpInfo.netmask));
            wifiListStr.put("Server IP", Formatter.formatIpAddress(dhcpInfo.serverAddress));
            wifiListStr.put("Lease Time(sec)", String.valueOf(dhcpInfo.leaseDuration));

            WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
            if (wifiInfo != null) {
                wifiListStr.put("LinkSpeed Mbps", String.valueOf(wifiInfo.getLinkSpeed()));
                int numberOfLevels = 10;
                int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1);
                wifiListStr.put("Signal%", String.valueOf(100 * level / numberOfLevels));
                if (Build.VERSION.SDK_INT >= 23) {
                    wifiListStr.put("MAC", getMacAddr());
                } else {
                    wifiListStr.put("MAC", wifiInfo.getMacAddress());
                }
            }

        } catch (Exception ex) {
            m_log.e("Wifi %s", ex.getMessage());
        }

        if (!wifiListStr.isEmpty()) {
            addBuild("WiFi...", wifiListStr);
        }

        try {
            if (ActivityCompat.checkSelfPermission(getContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(getContext(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                List<ScanResult> listWifi = wifiMgr.getScanResults();
                if (listWifi != null && !listWifi.isEmpty()) {
                    int idx = 0;

                    for (ScanResult scanResult : listWifi) {
                        Map<String, String> wifiScanListStr = new LinkedHashMap<String, String>();
                        wifiScanListStr.put("SSID", scanResult.SSID);
                        if (Build.VERSION.SDK_INT >= 23) {
                            wifiScanListStr.put("  Name", scanResult.operatorFriendlyName.toString());
                            wifiScanListStr.put("  Venue", scanResult.venueName.toString());
                        }

                        //        wifiScanListStr.put("  BSSID ",scanResult.BSSID);
                        wifiScanListStr.put("  Capabilities", scanResult.capabilities);
                        //       wifiScanListStr.put("  Center Freq", String.valueOf(scanResult.centerFreq0));
                        //       wifiScanListStr.put("  Freq width", String.valueOf(scanResult.channelWidth));
                        wifiScanListStr.put("  Level, Freq",
                                String.format("%d, %d", scanResult.level, scanResult.frequency));
                        if (Build.VERSION.SDK_INT >= 17) {
                            Date wifiTime = new Date(scanResult.timestamp);
                            wifiScanListStr.put("  Time", wifiTime.toLocaleString());
                        }
                        addBuild(String.format("WiFiScan #%d", ++idx), wifiScanListStr);
                    }
                }
            }
        } catch (Exception ex) {
            m_log.e("WifiList %s", ex.getMessage());
        }

        try {
            List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks();

            for (WifiConfiguration wifiCfg : listWifiCfg) {
                Map<String, String> wifiCfgListStr = new LinkedHashMap<String, String>();
                if (Build.VERSION.SDK_INT >= 23) {
                    wifiCfgListStr.put("Name", wifiCfg.providerFriendlyName);
                }
                wifiCfgListStr.put("SSID", wifiCfg.SSID);
                String netStatus = "";
                switch (wifiCfg.status) {
                case WifiConfiguration.Status.CURRENT:
                    netStatus = "Connected";
                    break;
                case WifiConfiguration.Status.DISABLED:
                    netStatus = "Disabled";
                    break;
                case WifiConfiguration.Status.ENABLED:
                    netStatus = "Enabled";
                    break;
                }
                wifiCfgListStr.put(" Status", netStatus);
                wifiCfgListStr.put(" Priority", String.valueOf(wifiCfg.priority));
                if (null != wifiCfg.wepKeys) {
                    //               wifiCfgListStr.put(" wepKeys", TextUtils.join(",", wifiCfg.wepKeys));
                }
                String protocols = "";
                if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.RSN))
                    protocols = "RSN ";
                if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.WPA))
                    protocols = protocols + "WPA ";
                wifiCfgListStr.put(" Protocols", protocols);

                String keyProt = "";
                if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE))
                    keyProt = "none";
                if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP))
                    keyProt = "WPA+EAP ";
                if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK))
                    keyProt = "WPA+PSK ";
                wifiCfgListStr.put(" Keys", keyProt);

                if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) {
                    // Remove network connections with no Password.
                    // wifiMgr.removeNetwork(wifiCfg.networkId);
                }

                addBuild("WiFiCfg #" + wifiCfg.networkId, wifiCfgListStr);
            }

        } catch (Exception ex) {
            m_log.e("Wifi Cfg List %s", ex.getMessage());
        }
    }

    if (expandAll) {
        // updateList();
        int count = m_list.size();
        for (int position = 0; position < count; position++)
            m_listView.expandGroup(position);
    }

    m_adapter.notifyDataSetChanged();
}