Java Code Examples for android.bluetooth.BluetoothDevice#getName()

The following examples show how to use android.bluetooth.BluetoothDevice#getName() . 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: ScannerFragment.java    From neatle with MIT License 8 votes vote down vote up
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.mItem = mValues.get(position);

    ScanEvent e = mValues.get(position);
    BluetoothDevice device = e.getDevice();
    String name = device.getName();
    if (name == null || name.length() == 0) {
        name = "No name";
    }

    holder.mIdView.setText(name);
    holder.mContentView.setText("MAC: " + device.getAddress() + ", rssi:" + e.getRssi());

    holder.mView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mListener) {
                // Notify the active callbacks interface (the activity, if the
                // fragment is attached to one) that an item has been selected.
                mListener.onDeviceSelected(holder.mItem.getDevice());
            }
        }
    });
}
 
Example 2
Source File: PBluetoothLE.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
    MLog.d(TAG, "found device " + device.getAddress() + " " + rssi);

    ReturnObject o = new ReturnObject();
    String name = device.getName();
    if (name == null) name = "";

    o.put("name", name);
    o.put("mac", device.getAddress());
    o.put("rssi", rssi);
    o.put("device", device);

    mHandler.post(() -> {
        mCallbackScan.event(o);
    });
}
 
Example 3
Source File: AppBleService.java    From bleYan with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 如果通过BleService扫描设备,回调方法
 *
 * @param device     Identifies the remote device
 * @param rssi       The RSSI value for the remote device as reported by the
 *                   Bluetooth hardware. 0 if no RSSI value is available.
 * @param scanRecord The content of the advertisement record offered by
 */
@Override
public void onBleScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
    synchronized (this) {
        //状态已更新,停止扫描...
        if (mState != BleConnectState.SCANNING) {
            stopScan();
            return;
        }
        BleLog.i(TAG, "onScan " + device + " " + rssi);
        if (device != null && device.getName() != null) {

            if (rssi < -90) {//弱信号
                return;
            }

            //是否 需要去连接~
            updateState(BleConnectState.CONNECTING);
            stopScan();

            BleLog.i(TAG, "connect " + device.getAddress());
            connectDevice(device);
        }
    }
}
 
Example 4
Source File: BluetoothActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
@Override
public void onBluetoothClick(BluetoothDevice device) {
    if (device != null) {
        if (!lastDeviceAddress.equals(device.getAddress()))
            mService.initiativeStop();
        mService.connect(device);
        lastDeviceAddress = device.getAddress();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
        if (currentFragment.getTag().equals(LIST_FRAGMENT))
            transaction.hide(currentFragment);
        Fragment fragment = getSupportFragmentManager().findFragmentByTag(CHAT_FRAGMENT);
        ((BluetoothChatFragment) fragment).setDeviceAddress(lastDeviceAddress);
        if (!fragment.isAdded())
            transaction.add(fragment, CHAT_FRAGMENT);
        transaction.show(fragment);
        currentFragment = fragment;
        transaction.commit();
        String subtitle = device.getName();
        if (TextUtils.isEmpty(subtitle))
            subtitle = lastDeviceAddress;
        setSubtitle(subtitle);
    }
}
 
Example 5
Source File: ManufacturerRecordParserFactory.java    From BLExplorer with GNU General Public License v3.0 5 votes vote down vote up
public String getName(BluetoothDevice device) {
    if (TextUtils.isEmpty(device.getName())) {
        return "no name";
    } else {
        return device.getName();
    }
}
 
Example 6
Source File: DevicesFragment.java    From SimpleBluetoothLeTerminal with MIT License 5 votes vote down vote up
/**
 * sort by name, then address. sort named devices first
 */
static int compareTo(BluetoothDevice a, BluetoothDevice b) {
    boolean aValid = a.getName()!=null && !a.getName().isEmpty();
    boolean bValid = b.getName()!=null && !b.getName().isEmpty();
    if(aValid && bValid) {
        int ret = a.getName().compareTo(b.getName());
        if (ret != 0) return ret;
        return a.getAddress().compareTo(b.getAddress());
    }
    if(aValid) return -1;
    if(bValid) return +1;
    return a.getAddress().compareTo(b.getAddress());
}
 
Example 7
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void startSyncProxyService() {
	boolean isPaired = false;
	BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();

	if( btAdapter != null ) {
		if( btAdapter.isEnabled() && btAdapter.getBondedDevices() != null && !btAdapter.getBondedDevices().isEmpty() ) {
			for( BluetoothDevice device : btAdapter.getBondedDevices() ) {
				if( device.getName() != null && device.getName().contains( getString( R.string.device_name ) ) ) {
					isPaired = true;
					break;
				}
			}
		}

		if( isPaired ) {
			if( AppLinkService.getInstance() == null ) {
				Intent appLinkServiceIntent = new Intent( this, AppLinkService.class );
				startService( appLinkServiceIntent );
			} else {
				SyncProxyALM proxyInstance = AppLinkService.getInstance().getProxy();
				if( proxyInstance == null ) {
					AppLinkService.getInstance().startProxy();
				}
			}
		}
	}
}
 
Example 8
Source File: Bluetooth.java    From Makeblock-App-For-Android with MIT License 5 votes vote down vote up
public List<String> getPairedList(){
       List<String> data = new ArrayList<String>();
       Set<BluetoothDevice> pairedDevices = mBTAdapter.getBondedDevices();
       prDevices.clear();
	if (pairedDevices.size() > 0) {
           for (BluetoothDevice device : pairedDevices) {
               prDevices.add(device);
           }
       }
       for(BluetoothDevice dev : prDevices){
       	String s = dev.getName();
       	s=s+" "+dev.getAddress();
       	if(connDev!=null && connDev.equals(dev)){
       		s="-> "+s;
       	}
       	data.add(s);
       }
       return data;
}
 
Example 9
Source File: ScannedDevice.java    From M365-Power with GNU General Public License v3.0 5 votes vote down vote up
public ScannedDevice(BluetoothDevice device, int rssi) {
    if (device == null) {
        throw new IllegalArgumentException("BluetoothDevice is null");
    }
    mDevice = device;
    mDisplayName = device.getName();
    if ((mDisplayName == null) || (mDisplayName.length() == 0)) {
        mDisplayName = UNKNOWN;
    }
    mRssi = rssi;
}
 
Example 10
Source File: ESenseScanner.java    From flutter-plugins with MIT License 5 votes vote down vote up
@Override
public void onScanResult(int callbackType, ScanResult result) {
    super.onScanResult(callbackType, result);
    BluetoothDevice _device = result.getDevice();
    if (_device != null && _device.getName() != null && _device.getName().matches(mDeviceName)) {
        stopScan();
        mDevice = _device;

        Log.i(TAG,"mac address : " + mDevice.getAddress() + ", name : " + mDevice.getName());
        mDeviceFoundLatch.countDown();
    }
}
 
Example 11
Source File: BLEService.java    From android_wear_for_ios with MIT License 5 votes vote down vote up
@Override
        public void onScanResult(int callbackType, android.bluetooth.le.ScanResult result) {
            Log.d(TAG_LOG, "scan result" + result.toString());

            BluetoothDevice device = result.getDevice();

            if (!is_connect) {
                Log.d(TAG_LOG, "is connect");
                if (device != null) {
                    Log.d(TAG_LOG, "device ");
                    if (!is_reconnect && device.getName() != null) {
                        if(device.getName().equals("Blank")) {
//                        if(device.getName().equals("BLE Utility")) {
                            Log.d(TAG_LOG, "getname ");
                            iphone_uuid = device.getAddress().toString();
                            is_connect = true;
                            bluetooth_gatt = result.getDevice().connectGatt(getApplicationContext(), false, bluetooth_gattCallback);
                        }
                    } else if (is_reconnect && device.getAddress().toString().equals(iphone_uuid)) {
                        if(!is_time) {
                            Log.d(TAG_LOG, "-=-=-=-=-=-=-=-=-=- timer start:: -=-==-=-=-=-=-=-==--=-=-=-==-=-=-=-=-=-=-=-");
                            start_time = System.currentTimeMillis();
                            is_time = true;
                        }else if(System.currentTimeMillis() - start_time > 5000){
                            Log.d(TAG_LOG, "-=-=-=-=-=-=-=-=-=- reconnect:: -=-==-=-=-=-=-=-==--=-=-=-==-=-=-=-=-=-=-=-");
                            is_connect = true;
                            is_reconnect = false;
                            bluetooth_gatt = device.connectGatt(getApplicationContext(), true, bluetooth_gattCallback);
                        }
                    } else {
                        Log.d(TAG_LOG, "skip:: ");
                        skip_count++;
                    }
                }
            }
        }
 
Example 12
Source File: Amazfitservice.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public String getCurrentDevice() {
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    String currentdevice;
    if (activeBluetoothDevice != null) {
        currentdevice = activeBluetoothDevice.name;
    } else {
        currentdevice = "None Set";
    }

    String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
    if (collection_method.compareTo("DexcomG5") == 0) {
        Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
        if (Build.VERSION.SDK_INT >= 18) {
            mBluetoothAdapter = mBluetoothManager.getAdapter();
        }
        if (mBluetoothAdapter != null) {
            Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
            if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
                for (BluetoothDevice device : pairedDevices) {
                    if (device.getName() != null) {

                        String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                        String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());

                        if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                            currentdevice = defaultTransmitter.transmitterId;
                        }

                    }
                }
            }
        } else {
            currentdevice = "No Bluetooth";
        }
    }
    return currentdevice;
}
 
Example 13
Source File: SystemStatusFragment.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void setConnectionStatus() {
    boolean connected = false;
    if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) {
        for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
            if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
                connected = true;
            }
        }
    }
    if (connected) {
        connection_status.setText(safeGetContext().getString(R.string.connected));
    } else {
        connection_status.setText(safeGetContext().getString(R.string.not_connected));
    }

    String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
    if (collection_method.compareTo("DexcomG5") == 0) {
        Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
        if (Build.VERSION.SDK_INT >= 18) mBluetoothAdapter = mBluetoothManager.getAdapter();
        if (mBluetoothAdapter != null) {
            Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
            if (pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {
                    if (device.getName() != null) {

                        String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                        String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());

                        if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                            final String fw = G5CollectionService.getFirmwareVersionString(defaultTransmitter.transmitterId);
                            connection_status.setText(device.getName() + " Authed" + ((fw != null) ? ("\n" + fw) : ""));
                            break;
                        }

                    }
                }
            }
        } else {
            connection_status.setText(safeGetContext().getString(R.string.no_bluetooth)); 
        }
    }
}
 
Example 14
Source File: MultiplexBluetoothTransport.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Start the ConnectedThread to begin managing a Bluetooth connection
 * @param socket  The BluetoothSocket on which the connection was made
 * @param device  The BluetoothDevice that has been connected
 */
@RequiresPermission(Manifest.permission.BLUETOOTH)
public synchronized void connected(BluetoothSocket socket, BluetoothDevice device) {
    // Cancel the thread that completed the connection
    if (mConnectThread != null) {
    	mConnectThread.cancel();
    	mConnectThread = null;
    }
    
    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
    	mConnectedThread.cancel(); 
    	mConnectedThread = null;
    }
    if (mConnectedWriteThread != null) {
    	mConnectedWriteThread.cancel(); 
    	mConnectedWriteThread = null;
    }
    // Cancel the accept thread because we only want to connect to one device
    if (!keepSocketAlive && mSecureAcceptThread != null) {
    	mSecureAcceptThread.cancel();
        mSecureAcceptThread = null;
    }

    // Start the thread to manage the connection and perform transmissions
    mConnectedThread = new ConnectedThread(socket);
    mConnectedThread.start();
    // Start the thread to manage the connection and perform transmissions
    mConnectedWriteThread = new ConnectedWriteThread(socket);
    mConnectedWriteThread.start();

    //Store a static name of the device that is connected.
    if(device != null){
    	connectedDeviceName = device.getName();
        connectedDeviceAddress = device.getAddress();
        if(connectedDeviceAddress!=null){
            //Update the transport record with the address
            transportRecord = new TransportRecord(transportType, connectedDeviceAddress);
        }
    }
    
    // Send the name of the connected device back to the UI Activity
    Message msg = handler.obtainMessage(SdlRouterService.MESSAGE_DEVICE_NAME);
    Bundle bundle = new Bundle();
    if(connectedDeviceName != null) {
        bundle.putString(DEVICE_NAME, connectedDeviceName);
        bundle.putString(DEVICE_ADDRESS, connectedDeviceAddress);
    }
    msg.setData(bundle);
    handler.sendMessage(msg);
    setState(STATE_CONNECTED);
}
 
Example 15
Source File: AddVoiceSettingActivity.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
private void populateBtDevices(int spinnerViewId, int checkBoxViewId, VoiceSettingParamType voiceSettingParamType) {
    MultiSelectionSpinner btDevicesSpinner = findViewById(spinnerViewId);
    CheckBox allBtCheckbox = findViewById(checkBoxViewId);
    View btDevicePanel = findViewById(R.id.tts_bt_device_panel);
    btDevicesSpinner.setVoiceSettingId(voiceSettingId);

    BluetoothAdapter bluetoothAdapter = Utils.getBluetoothAdapter(getBaseContext());

    if (bluetoothAdapter == null) {
        btDevicesSpinner.setVisibility(View.GONE);
        allBtCheckbox.setVisibility(View.GONE);
        btDevicePanel.setVisibility(View.GONE);
        return;
    } else {
        btDevicesSpinner.setVisibility(View.VISIBLE);
        allBtCheckbox.setVisibility(View.VISIBLE);
        btDevicePanel.setVisibility(View.VISIBLE);
    }

    Set<BluetoothDevice> bluetoothDeviceSet = bluetoothAdapter.getBondedDevices();

    ArrayList<MultiselectionItem> items = new ArrayList<>();
    ArrayList<MultiselectionItem> selection = new ArrayList<>();
    ArrayList<String> selectedItems = new ArrayList<>();

    String enabledBtDevices = voiceSettingParametersDbHelper.getStringParam(
            voiceSettingId,
            voiceSettingParamType.getVoiceSettingParamTypeId());
    Boolean enabledVoiceDevices = voiceSettingParametersDbHelper.getBooleanParam(
            voiceSettingId,
            voiceSettingParamType.getVoiceSettingParamTypeId());
    if ((enabledVoiceDevices != null) && enabledVoiceDevices) {
        allBtCheckbox.setChecked(true);
        findViewById(R.id.bt_when_devices).setVisibility(View.GONE);
    } else {
        findViewById(R.id.bt_when_devices).setVisibility(View.VISIBLE);
    }

    if (enabledBtDevices != null) {
        for (String btDeviceName: enabledBtDevices.split(",")) {
            selectedItems.add(btDeviceName);
        }
    }

    for(BluetoothDevice bluetoothDevice: bluetoothDeviceSet) {
        String currentDeviceName = bluetoothDevice.getName();
        String currentDeviceAddress = bluetoothDevice.getAddress();
        MultiselectionItem multiselectionItem;
        if (selectedItems.contains(currentDeviceAddress)) {
            multiselectionItem = new MultiselectionItem(currentDeviceName, currentDeviceAddress, true);
            selection.add(multiselectionItem);
        } else {
            multiselectionItem = new MultiselectionItem(currentDeviceName, currentDeviceAddress,false);
        }
        items.add(multiselectionItem);
    }
    btDevicesSpinner.setItems(items);
    btDevicesSpinner.setSelection(selection);
}
 
Example 16
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void initScanCallback(){
        mScanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                UserError.Log.i(TAG, "result: " + result.toString());
                BluetoothDevice btDevice = result.getDevice();
//                // Check if the device has a name, the Dexcom transmitter always should. Match it with the transmitter id that was entered.
//                // We get the last 2 characters to connect to the correct transmitter if there is more than 1 active or in the room.
//                // If they match, connect to the device.
                if (btDevice.getName() != null) {
                    String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                    String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(btDevice.getName());

                    if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                        if (advertiseTimeMS.size() > 0)
                            if ((new Date().getTime() - advertiseTimeMS.get(advertiseTimeMS.size()-1)) > 2.5*60*1000)
                                advertiseTimeMS.clear();
                        advertiseTimeMS.add(new Date().getTime());
                        isIntialScan = false;
                        //device = btDevice;
                        device = mBluetoothAdapter.getRemoteDevice(btDevice.getAddress());
                        static_device_address = btDevice.getAddress();
                        stopScan();
                        connectToDevice(btDevice);
                    } else {
                        //stopScan(10000);
                    }
                }
            }

            @Override
            public void onScanFailed(int errorCode) {
                Log.e(TAG, "Scan Failed Error Code: " + errorCode);
                if (errorCode == 1) {
                    UserError.Log.e(TAG, "Already Scanning: " + isScanning);
                    //isScanning = true;
                } else if (errorCode == 2){
                    cycleBT();
                }
            }
        };
    }
 
Example 17
Source File: ExtendedBluetoothDevice.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ExtendedBluetoothDevice(@NonNull final BluetoothDevice device) {
	this.device = device;
	this.name = device.getName();
	this.rssi = NO_RSSI;
	this.isBonded = true;
}
 
Example 18
Source File: IBeaconProtocol.java    From ibeacon-android-library with Apache License 2.0 4 votes vote down vote up
@Override
  public void onLeScan(final BluetoothDevice device, int rssi,
          byte[] scanRecord) {
  	
Log.i(Utils.LOG_TAG,"BLE packet received");
  	
  	IBeacon newBeacon = parseAdvertisementData(scanRecord);
  	if(newBeacon == null)
  		return;
  	
  	newBeacon.setMacAddress(device.getAddress());

  	// If already discovered, then just refresh the RSSI of the existing instance and return
  	if(_arrOrderedIBeacons.contains(newBeacon)){
  		int newDistance = (int)calculateDistance(newBeacon.getPowerValue(), rssi);
  		IBeacon previousIBeaconInfo = findIfExists(newBeacon);
  		int oldDistance = previousIBeaconInfo.getProximity();
  		if(newDistance < oldDistance){
  			Log.i(Utils.LOG_TAG,"Updating distance");
  			previousIBeaconInfo.setProximity(newDistance);
   		// Sort again
    	Collections.sort(_arrOrderedIBeacons, new IBeaconProximityComparator());
  		}
  		return;
  	}
  	
 		newBeacon.setEasiBeacon(false);
  	if(device.getName() != null){
   	if(device.getName().startsWith(EASIBEACON_IDPREFIX)){
   		newBeacon.setEasiBeacon(true);
   		String version = device.getName().substring(EASIBEACON_IDPREFIX.length());
   		newBeacon.setVersionModel(version);
   		if(newBeacon.getVersion() == 1){
   			// Version 1 is always connectable
   			newBeacon.setConnectable(true);
   		}else if(newBeacon.getVersion() == 2){
   			newBeacon.setConnectable(getConnectable(scanRecord));
   			if(!newBeacon.isConnectable())
   				newBeacon.setEasiBeacon(false); //If not connectable we will report it as unknown 
   		}		    		
   	}
  	}
  	// Review this
  	Log.i(Utils.LOG_TAG,device.getName() + " " + device.getAddress() + " " + newBeacon.getPowerValue() + " " + rssi + " Connectable: " + newBeacon.isConnectable());
  	newBeacon.setProximity((int)calculateDistance(newBeacon.getPowerValue(), rssi));
  	
  	if(!_arrOrderedIBeacons.contains(newBeacon)){
   	_arrOrderedIBeacons.add(newBeacon);
   	Collections.sort(_arrOrderedIBeacons, new IBeaconProximityComparator());
   	_listener.beaconFound(newBeacon);
   	
   	// Every time a new beacon is found, reset the timeout
   	_timeoutHandler.removeCallbacks(timeoutTask);
	_timeoutHandler.postDelayed(timeoutTask, IBeaconProtocol.SCANNING_PERIOD);

  	} 	
 }
 
Example 19
Source File: BluetoothLEScanCallback21.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
public void onScanResult(int callbackType, ScanResult result) {
    //CallsCounter.logCounter(context, "BluetoothLEScanCallback21.onScanResult", "BluetoothLEScanCallback21.onScanResult");

    final BluetoothDevice _device = result.getDevice();

    if (_device == null)
        return;

    //final Context appContext = context.getApplicationContext();

    if (!PPApplication.getApplicationStarted(true))
        // application is not started
        return;
    if (ApplicationPreferences.prefForceOneBluetoothScan != BluetoothScanner.FORCE_ONE_SCAN_FROM_PREF_DIALOG) {
        if (!ApplicationPreferences.applicationEventBluetoothEnableScanning)
            // scanning is disabled
            return;
    }

    //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "xxx");

    //boolean scanStarted = (BluetoothScanWorker.getWaitForLEResults(context));
    //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "scanStarted=" + scanStarted);

    //if (scanStarted) {
    //PPApplication.logE("BluetoothLEScanCallback21", "onScanResult - callbackType=" + callbackType);
    //PPApplication.logE("BluetoothLEScanCallback21", "onScanResult - result=" + result.toString());

    //String btAddress = _device.getAddress();
    String btName = _device.getName();
    //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "deviceAddress=" + btAddress);
    //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "deviceName=" + btName);

    BluetoothDeviceData deviceData = new BluetoothDeviceData(btName, _device.getAddress(),
            BluetoothScanWorker.getBluetoothType(_device), false, 0, false, true);

    BluetoothScanWorker.addLEScanResult(deviceData);

    /*
    PPApplication.startHandlerThreadBluetoothLECallback();
    final Handler handler = new Handler(PPApplication.handlerThreadBluetoothLECallback.getLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            PowerManager powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wakeLock = null;
            try {
                if (powerManager != null) {
                    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PPApplication.PACKAGE_NAME + ":BluetoothLEScanBroadcastReceiver21_onScanResult");
                    wakeLock.acquire(10 * 60 * 1000);
                }

                //PPApplication.logE("PPApplication.startHandlerThread", "START run - from=BluetoothLEScanCallback21.onScanResult");

                //boolean scanStarted = (BluetoothScanWorker.getWaitForLEResults(context));
                //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "scanStarted=" + scanStarted);

                //if (scanStarted) {
                    //PPApplication.logE("BluetoothLEScanCallback21", "onScanResult - callbackType=" + callbackType);
                    //PPApplication.logE("BluetoothLEScanCallback21", "onScanResult - result=" + result.toString());

                    //String btAddress = _device.getAddress();
                    String btName = _device.getName();
                    //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "deviceAddress=" + btAddress);
                    //PPApplication.logE("BluetoothLEScanCallback21.onScanResult", "deviceName=" + btName);

                    BluetoothDeviceData deviceData = new BluetoothDeviceData(btName, _device.getAddress(),
                            BluetoothScanWorker.getBluetoothType(_device), false, 0, false, true);

                    BluetoothScanWorker.addLEScanResult(deviceData);
                //}

                //PPApplication.logE("PPApplication.startHandlerThread", "END run - from=BluetoothLEScanCallback21.onScanResult");
            } finally {
                if ((wakeLock != null) && wakeLock.isHeld()) {
                    try {
                        wakeLock.release();
                    } catch (Exception ignored) {}
                }
            }
        }
    });
    */
}
 
Example 20
Source File: BluetoothScan.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Log.d(TAG, "Item Clicked");
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null || device.getName() == null) return;
    Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show();

    ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
            .orderBy("_ID desc")
            .executeSingle();

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    prefs.edit().putString("last_connected_device_address", device.getAddress()).apply();
    if (btDevice == null) {
        ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
        newBtDevice.name = device.getName();
        newBtDevice.address = device.getAddress();
        newBtDevice.save();
    } else {
        btDevice.name = device.getName();
        btDevice.address = device.getAddress();
        btDevice.save();
    }
    if(device.getName().toLowerCase().contains("dexcom")) {
        if(!CollectionServiceStarter.isBTShare(getApplicationContext())) {
            prefs.edit().putString("dex_collection_method", "DexcomShare").apply();
            prefs.edit().putBoolean("calibration_notifications", false).apply();
        }
        if(prefs.getString("share_key", "SM00000000").compareTo("SM00000000") == 0 || prefs.getString("share_key", "SM00000000").length() < 10) {
            requestSerialNumber(prefs);
        } else returnToHome();

    } else if(device.getName().toLowerCase().contains("bridge")) {
        if(!CollectionServiceStarter.isDexbridgeWixelorWifiandDexbridgeWixel(getApplicationContext()))
            prefs.edit().putString("dex_collection_method", "DexbridgeWixel").apply();
        if(prefs.getString("dex_txid", "00000").compareTo("00000") == 0 || prefs.getString("dex_txid", "00000").length() < 5) {
            requestTransmitterId(prefs);
        } else returnToHome();

    } else if(device.getName().toLowerCase().contains("drip")) {
        if (!
                (CollectionServiceStarter.isBteWixelorWifiandBtWixel(getApplicationContext())
                ) || CollectionServiceStarter.isLimitter(getApplicationContext())) {
            prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply();
        }
        returnToHome();
    } else if(device.getName().toLowerCase().contains("limitter")) {
        if (!CollectionServiceStarter.isLimitter(getApplicationContext())) {
            prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
        }
        returnToHome();
    } else {
        returnToHome();
    }
}