android-bluetooth

Detect if bluetooth headset connected

两盒软妹~` 提交于 2019-12-05 14:15:45
Working on a VOIP application, in silent mode an alert tone or ringtone should play on bluetooth headset only. Able to play it on headphone if connected but if the headset is not connected the tone plays on the speaker though the mobile is in silent mode. Someone please explain if there is a way to detect that a bluetooth headset is connected. For Bluetooth Headset you can use getConnectedDevices() Reference: http://developer.android.com/reference/android/bluetooth/BluetoothHeadset.html Here is my code: /** */ class BluetoothStateMonitor(private val appContext: Context): BroadcastReceiver(),

Connecting to Bluetooth device fails in deep sleep

送分小仙女□ 提交于 2019-12-05 13:09:25
I'm attempting to connect to a paired bluetooth device every 25 seconds, scheduled through AlarmManager which triggers a WakefulBroadcastReceiver to start a service to do the connection. Once the device goes to sleep, everything works great for the first few hours, but it starts to fail after about 4-5 hours, when I assume the device goes into a deep sleep . I get a NullPointerException from ParcelFileDescriptor, stating the "FileDescriptor must not be null". I've tried searching this error, and have even gone through the code in ParcelFileDescriptor.java, but am at a dead end. I'm running

BLuetooth Gatt Callback not working with new API for Lollipop

大兔子大兔子 提交于 2019-12-05 12:59:15
问题 I currently have a method which writes to the BLE devices to beep it. My Bluetooth Callback goes as follows : ReadCharacteristic rc = new ReadCharacteristic(context, ds.getMacAddress(), serviceUUID, UUID.fromString(myUUID), "") { @Override public void onRead() { Log.w(TAG, "callDevice onRead"); try{Thread.sleep(1000);}catch(InterruptedException ex){} WriteCharacteristic wc = new WriteCharacteristic(activity, context, getMacAddress(), serviceUUID, UUID.fromString(myUUID), ""){ @Override public

BLE Scan Record Explanation

元气小坏坏 提交于 2019-12-05 11:31:34
I am trying to get the UUID , Major , Minor IDs from the BLE advertisement received in the form of a byte[] . I have used the suggested code here but the i am unable to understand the output of the parser. Here is the output i get for one of the BLE devices Length: 2 Type : 1 Data : 6, Length: 26 Type : -1 Data : 76 0 2 21 -9 -126 109 -90 79 -94 78 -104 -128 36 -68 91 113 -32 -119 62 12 -121 -79 52 -77, Length: 8 Type : 9 Data : 75 111 110 116 97 107 116, Length: 2 Type : 10 Data : -12, Length: 10 Type : 22 Data : 13 -48 117 76 106 98 50 55 100 How to understand which field contains the UUID ,

GATT over SPP profile for bluetooth communication?

馋奶兔 提交于 2019-12-05 10:32:13
This is confusing me for days. In the beginning when I was implementing the functionality, I used GATT profile for BLE bluetooth communication. Then I came up with BluetoothSocket . This uses the SPP profile for bluetooth communication. There is mentioned: The most common type of Bluetooth socket is RFCOMM, which is the type supported by the Android APIs. RFCOMM is a connection-oriented, streaming transport over Bluetooth. It is also known as the Serial Port Profile (SPP). My requirement is - 1) To scan and then connect my android device with the Black Box using BLE bluetooth. 2) Then initiate

How to get BluetoothGattCharacteristic value format type?

[亡魂溺海] 提交于 2019-12-05 03:49:29
问题 While developing an application for IOT tried communicating with a BLE peripheral device. Using BLE Lollipop API. Each BluetoothGattService can provide different BluetoothGattCharacteristic, each representing a certain value which can be Read, Write or Notified. Value is communicated in various formats. But there is no way to know which format a particular Characteristic is encoded in. I thought this mKeySize could be a solution but, it is neither accessible nor being used inside

startVoiceRecognition with bluetooth headset is not working

偶尔善良 提交于 2019-12-05 03:09:51
I need to use bluetooth headset with voice recognition, which almost works fine in some devices like S3, S4 and Samsung Grand. However, when I tried same on Nexus 7, I am getting BluetoothHeadsetServiceJni : Failed to start voice recognition, status: 6 error when I am calling startVoiceRecognition() method. I am using the code from this SO page . What are the possible reasons for this issue occur only in some devices? Is there any way to solve this issue? I have been check as Narayan mentioned, I found BluetoothHeadset.STATE_AUDIO_CONNECTED does fire in nexus 7 as well some other ZTE devices,

What is the proper method for reading a GATT characteristic in Android?

只谈情不闲聊 提交于 2019-12-05 01:27:01
In attempting to read the value of a Bluetooth Low-Energy GATT characteristic in the Android API 18, I came across the following dilemma: What is the proper way to retrieve the value stored in a characteristic? And at which level of the stack should this action take place? In conducting my own research, I stumbled upon what I understand are two possible methods: BluetoothGatt .readCharacteristic(BluetoothGattCharacteristic characteristic) BluetoothGattCharacteristic .getValue() public void onClick(View v){ byteValue = mBTValueCharacteristic.getValue(); if ((byteValue[0] & 0x01) == 1) byteValue

Sending File via Bluetooth using Intent Action SEND does not working in android 4.2.2?

只谈情不闲聊 提交于 2019-12-04 21:23:44
I have used Intent-SEND to share the files via bluetooth.I have add my code here. Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setComponent(new ComponentName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity")); intent.setType("text/plain"); File file = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/Sample.txt"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); startActivity(intent); This code is not working in android version 4.2.2. While running this code in android verison 4.2.2 , getting

Connect to specific Bluetooth device with a click

落爺英雄遲暮 提交于 2019-12-04 19:45:54
I'm trying to connect to a specific device using my Android APP, until now what I was able to do is get the paired items doing this : BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set < BluetoothDevice > pairedDevices = bluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device: pairedDevices) { mDeviceName.add(device.getName()); mDeviceMAC.add(device.getAddress()); } } bluetoothClass.setDeviceName(mDeviceName); bluetoothClass.setDeviceMac(mDeviceMAC); Where I get the MAC and the Device name of all of my paired devices. The