android-bluetooth

How to detect when a BLE device is not in range anymore?

倖福魔咒の 提交于 2019-11-28 19:20:16
I use a LeScanCallback (can not use the newer scan methods because I'm developing for api 18. Not that it matters, since the android 5.0+ apis don't offer this functionality either) to detect when a nearby BLE device is detected: private BluetoothAdapter.LeScanCallback bleCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) { discoveredDevices.add(bluetoothDevice); } }; I am not pairing or connecting with the devices because that's not required, I simply want to see which devices are nearby. I'm trying to make a

How to stream audio from one Android device to another Android device Via Bluetooth?

帅比萌擦擦* 提交于 2019-11-28 16:24:19
Is it possible to stream audio over bluetooth? During my research I found that is it only possible using A2DP(Advanced Audio Distribution Profile) . And does every android device support A2DP? If not, is it possible to stream audio between two android devices using bluetooth? Please help me understand this. I've looked through the following links: Receive audio via Bluetooth in Android , Google confirms bluetooth audio streaming fix for next version of Android 4.2 How can I stream audio from another device via Bluetooth? Is it possible to stream audio over Bluetooth? Below sort of thread says

Android 6.0 Marshmallow BLE : Connection Parameters

偶尔善良 提交于 2019-11-28 15:12:10
问题 The Bluetooth Low Energy connection parameters management seems to have changed in Android 6. I have a BLE Peripheral device who needs to use some specific connection parameters (notably, the connection interval), and I want to use the minimum connection interval allowed by the BLE specification (i.e. 7,5ms). The Android SDK doesn't allow to choose it from the BLE GAP Central (the smartphone) side, so the proper way to do it is to make my GAP Peripheral device send a L2CAP Connection

Android Bluetooth Low Energy code compatible with API>=21 AND API<21

懵懂的女人 提交于 2019-11-28 11:33:20
I'm developing an app that have to connect with a BLE device, in my code I want to use the new Scan and ScanCallback for BLE implemented from API 21 (Android 5) but I have to maintain the compatibility with Android 4.3 and above. So I wrote the code, for example, in this way: if (Build.VERSION.SDK_INT >= 21) { mLEScanner.startScan(filters, settings, mScanCallback); } else { btAdapter.startLeScan(leScanCallback); } And I have defined the 2 callbacks, one for API 21 and above and one for API 18 to 20: //API 21 private ScanCallback mScanCallback = new ScanCallback() { @Override public void

Solution for BLE scan's SCAN_FAILED_APPLICATION_REGISTRATION_FAILED?

对着背影说爱祢 提交于 2019-11-28 10:57:13
My Android app scans BLE devices, and from a certain point it start to fails with error code 2 ( ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED ). I'm using Nexus 9, 5.0.1 Lollipop. This problem continued even after I relaunched the app, and when I restarted the Bluetooth service from Settings, I could finally get rid of the problem. But this problem is recurring, and I think I'm coding in a wrong way; BLE related APIs are new and there is few information. Does anyone know a general solution for this error, preferably not requiring restart of the Bluetooth service? Even though this

Android - Get Bluetooth UUID for this device

浪子不回头ぞ 提交于 2019-11-28 06:31:37
I was browing Stack and the internet for a simple solution to get the UUID of the device I'm currently using. I stumbled over posts like this but none of them seemed to help me. The doc tells me about this getUuids() function but when going through the doc for Android Bluetooth I end up having a BluetoothAdapter but I need a BluetoothDevice to execute this function. So I need to know the following: 1) Is the function returning really the device UUID ? Because the name saids plural (getUuid s ) 2) How do I get an instance of this BluetoothDevice ? Thanks! Using reflection you can invoke the

Android Bluetooth Pairing without User Enter Pin and Confirmation Using Android API

帅比萌擦擦* 提交于 2019-11-28 04:47:37
I'm a beginner in Android programming since I only started 3 months ago. I'm doing a project which connects the android app to arduino using bluetooth. I already have a code for the android app (bluetooth.adapter,sockets,.etc.). The code for connection is already working. One of the goal is for the android app to automatically input the password when pairing with the bluetooth device without asking user to input the PIN. The old posts on this forum do not help much. (many suggested using insecure mode, but I do need secure mode, also in my case, the arduino is the server while cellphone app is

What is “reliable write” in BLE?

若如初见. 提交于 2019-11-28 02:47:13
问题 In Android's BLE API (BluetoothGatt) there are methods that deal with reliable writes : public boolean beginReliableWrite () public void abortReliableWrite (BluetoothDevice mDevice) public boolean executeReliableWrite () There is also a Callback for it (in BluetoothGattCallback): public void onReliableWriteCompleted (BluetoothGatt gatt, int status) I can't find any documentation on that. What is it? How is it different from "normal" (unreliable?) writes? 回答1: Reliable write allows checking

Connect to Bluetooth programmatically

白昼怎懂夜的黑 提交于 2019-11-27 20:44:09
I'm trying to connect programmatically my device to for example on my Headsets... I had KitKat version and all worked perfect ( Bluetooth always was connecting without problems autommatically) but since I've updated to Lolipop it doesn't. I'd like to know if there is any way to connect any paired device of my Android phone to Bluetooth when it turns on. Since now I've this code (gets the Device name and Device Address) because I thought with it I could connect doing something like device.connect(MAC-Address); but it didn't work... BluetoothAdapter bluetoothAdapter = BluetoothAdapter

Programmatically connect to paired Bluetooth speaker and play audio

大憨熊 提交于 2019-11-27 18:16:43
问题 In our app, I'd like to connect to a previously paired A2DP Bluetooth Speaker and direct audio playback to it, using Android v4.2 or later. I can successfully create an A2DP profile object using this code to start the process: /* Manifest permissions */ <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> // Get the default adapter BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //