Search in sources :

Example 81 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothA2dpService method getDevicesMatchingConnectionStates.

public synchronized List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
    ArrayList<BluetoothDevice> sinks = new ArrayList<BluetoothDevice>();
    for (BluetoothDevice device : mAudioDevices.keySet()) {
        int sinkState = getConnectionState(device);
        for (int state : states) {
            if (state == sinkState) {
                sinks.add(device);
                break;
            }
        }
    }
    return sinks;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ArrayList(java.util.ArrayList)

Example 82 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothA2dpService method dump.

@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mAudioDevices.isEmpty())
        return;
    pw.println("Cached audio devices:");
    for (BluetoothDevice device : mAudioDevices.keySet()) {
        int state = mAudioDevices.get(device);
        pw.println(device + " " + BluetoothA2dp.stateToString(state));
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 83 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothBondState method setProfilePriorities.

// Set service priority of Hid, A2DP and Headset profiles depending on
// the bond state change
private void setProfilePriorities(String address, int state) {
    BluetoothDevice remoteDevice = mService.getRemoteDevice(address);
    // HID is handled by BluetoothService
    mBluetoothInputProfileHandler.setInitialInputDevicePriority(remoteDevice, state);
    //   incoming connection due to undefined priorities.
    if (state == BluetoothDevice.BOND_BONDED) {
        if (mA2dpProxy != null && mA2dpProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
            mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
        }
        if (mHeadsetProxy != null && mHeadsetProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
            mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
        }
    } else if (state == BluetoothDevice.BOND_NONE) {
        if (mA2dpProxy != null) {
            mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
        }
        if (mHeadsetProxy != null) {
            mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
        }
    }
    if (mA2dpProxy == null || mHeadsetProxy == null) {
        Log.e(TAG, "Proxy is null:" + mA2dpProxy + ":" + mHeadsetProxy);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 84 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project PairingExample by AinaWireless.

the class MainActivity method onCreate.

/* Setup example on application creation */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    boolean found = false;
    mText_classicMac = (TextView) findViewById(R.id.textView_classicMac);
    mText_bleMac = (TextView) findViewById(R.id.textView_bleMac);
    mText_charVal = (TextView) findViewById(R.id.textView_charVal);
    mText_keysString = (TextView) findViewById(R.id.textView_keysString);
    mText_sw_versions = (TextView) findViewById(R.id.sw_versions);
    mButton_scan = (Button) findViewById(R.id.ScanButton);
    mButton_rssi = (Button) findViewById(R.id.RSSIButton);
    /* Get bluetooth adapter */
    mAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mAdapter == null) {
        Toast.makeText(this, "Bluetooth not supported.", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    /* Check if bluetooth is enabled */
    if (!mAdapter.isEnabled()) {
        /* Request to start BT */
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, 1);
    }
    /* Needed by some Android versions */
    ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION }, 1001);
    scanResults = (TextView) findViewById(R.id.scan_results);
    scanHeader = (TextView) findViewById(R.id.scan_header);
    mButton_scan.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_PERMISSION);
        }
    });
    mButton_rssi.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mButton_rssi.setEnabled(false);
            if (Scanning == false) {
                scanHeader.setText("Scanning for devices and comparing rssi...");
                mAdapter.startLeScan(LeCallbackRSSI);
                Scanning = true;
            }
        }
    });
    detector = new BarcodeDetector.Builder(getApplicationContext()).setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE).build();
    if (!detector.isOperational()) {
        Toast.makeText(this, "Could not set up the QR-scanner!", Toast.LENGTH_LONG).show();
        mButton_scan.setEnabled(false);
        return;
    }
    /* Get NFC adapter */
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        Toast.makeText(this, "NFC not supported.", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    /* Check if NFC is enabled */
    if (!mNfcAdapter.isEnabled()) {
        Toast.makeText(this, "NFC is disabled.", Toast.LENGTH_LONG).show();
    } else {
        handleIntent(getIntent());
        mNfcActivity = this;
    }
    scanHeader.setText("QR-Code or NFC data not yet read...");
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    for (BluetoothDevice bt : pairedDevices) {
        if (bt.getAddress().toString().contains("38:B8:EB")) {
            MACs[1] = bt.getAddress().toString();
            mText_classicMac.setText("BTC MAC address = " + MACs[1]);
            mmDevice_classic = mBluetoothAdapter.getRemoteDevice(bt.getAddress().toString());
            found = true;
            PairedOnStart = true;
        }
    }
    if (found == true) {
        scanHeader.setText("No need for NFC or QR...");
        BTC_Connect = false;
        classic_paired = true;
        tryBLE = true;
        TextUpdateHandler.post(updateRunnable);
        read_ble_handler.postDelayed(runnable, 1000);
    }
}
Also used : BarcodeDetector(com.google.android.gms.vision.barcode.BarcodeDetector) BluetoothDevice(android.bluetooth.BluetoothDevice) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView)

Example 85 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by DirtyUnicorns.

the class ScanFilter method matches.

/**
     * Check if the scan filter matches a {@code scanResult}. A scan result is considered as a match
     * if it matches all the field filters.
     */
public boolean matches(ScanResult scanResult) {
    if (scanResult == null) {
        return false;
    }
    BluetoothDevice device = scanResult.getDevice();
    // Device match.
    if (mDeviceAddress != null && (device == null || !mDeviceAddress.equals(device.getAddress()))) {
        return false;
    }
    ScanRecord scanRecord = scanResult.getScanRecord();
    // Scan record is null but there exist filters on it.
    if (scanRecord == null && (mDeviceName != null || mServiceUuid != null || mManufacturerData != null || mServiceData != null)) {
        return false;
    }
    // Local name match.
    if (mDeviceName != null && !mDeviceName.equals(scanRecord.getDeviceName())) {
        return false;
    }
    // UUID match.
    if (mServiceUuid != null && !matchesServiceUuids(mServiceUuid, mServiceUuidMask, scanRecord.getServiceUuids())) {
        return false;
    }
    // Service data match
    if (mServiceDataUuid != null) {
        if (!matchesPartialData(mServiceData, mServiceDataMask, scanRecord.getServiceData(mServiceDataUuid))) {
            return false;
        }
    }
    // Manufacturer data match.
    if (mManufacturerId >= 0) {
        if (!matchesPartialData(mManufacturerData, mManufacturerDataMask, scanRecord.getManufacturerSpecificData(mManufacturerId))) {
            return false;
        }
    }
    // All filters match.
    return true;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)101 Intent (android.content.Intent)13 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)11 ParcelUuid (android.os.ParcelUuid)9 RemoteException (android.os.RemoteException)9 ScanFilter (android.bluetooth.le.ScanFilter)5 Parcel (android.os.Parcel)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)5 IntentFilter (android.content.IntentFilter)4 MidiDeviceInfo (android.media.midi.MidiDeviceInfo)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2