android-bluetooth

Programmatically connect to paired Bluetooth speaker and play audio

心已入冬 提交于 2019-11-30 13:01:45
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(); // Establish connection to the proxy. mBluetoothAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile

Accepting a Call via Bluetooth Headset

流过昼夜 提交于 2019-11-30 11:48:12
i am working on a VoIP-Android-App. I would like to accept and decline Calls via a connnected Bluetooth Headset in an Activity. What I have tried so far: Using a Media Session to receive Media Button clicks. Problem: If we start BluetoothSCO we do not receive any Media Button clicks. If we do not start BluetoothSCO we do receive Media Button clicks but we cannot differentiate long and short button clicks because downtime is always 0, the keycode is always KEYCODE_MEDIA_PLAY and the ACTION_DOWN is immediately followed by ACTION_UP. Those problems only occur if we are connected via Bluetooth. If

How to send data over a Bluetooth Low Energy (BLE) link?

孤街醉人 提交于 2019-11-30 10:39:47
问题 I am able to discover, connect to bluetooth. Source Code--- Connect via bluetooth to Remote Device: //Get the device by its serial number bdDevice = mBluetoothAdapter.getRemoteDevice(blackBox); //for ble connection bdDevice.connectGatt(getApplicationContext(), true, mGattCallback); Gatt CallBack for Status: private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { //Connection

The perfect function to check Android internet connectivity including bluetooth pan

不打扰是莪最后的温柔 提交于 2019-11-30 08:33:24
My application is working perfect in wifi and mobile networks, but fails to detect when connected through bluetooth tethering. public boolean isNetworkAvailable() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return true; } return false; } I tried running a few other applications . they also shows no network connectivity, But google applications works perfect and so as some other apps like whatsap. Wondering how they are doing it, and

Android how to read multiple BLE characteristics with a PriorityQueue

穿精又带淫゛_ 提交于 2019-11-30 07:15:56
A bit stuck here, might need your help. I want to read several BLE characteristics at once, some people suggest using PriorityQueue for that. I already know all the uuids, etc. just need a way to read several at once. Could anyone explain how exactly should it look like? Or maybe there is yet another easier solution? Thanks in advance, here is my code: public static final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { PriorityQueue<BluetoothGattCharacteristic> queue = new PriorityQueue<BluetoothGattCharacteristic>(); // When connection state changes @Override public void

How to call a MainActivity method from ViewHolder in RecyclerView.Adapter?

前提是你 提交于 2019-11-30 06:56:52
In a simple app project at GitHub I have only 2 custom Java-files: MainActivity.java contains Bluetooth- and UI-related source code DeviceListAdapter.java contains an Adapter and ViewHolder for displaying Bluetooth devices in a RecyclerView The MainActivity.java contains a method to be called, when user taps on a Bluetooth device in the RecyclerView : public void confirmConnection(String address) { final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Do you want to pair to " + device + "?");

Find already paired bluetooth devices automatically, when they are in range

五迷三道 提交于 2019-11-30 06:43:07
I am no Bluetooth specialist and wondering what possibilities are available to find already paired Bluetooth devices automatically when they are range of each other. Background : In our case an Android application needs to connect to a dedicated accessory via Bluetooth (Rfcomm). Both devices are known to each other (they are paired). The Android application registers a broadcast receiver. During the startup of the application, the app initiates a discovery to find the dedicated accessory. If the accessory is in range everything works great. Problem : The user starts the application outside the

Bluetooth not connecting on 4.4.2

北城余情 提交于 2019-11-30 06:01:48
I've got a Bluetooth device that has connected on all versions of Android that I have tried prior to 4.4.2. Now, it's not connecting on the Galaxy Tab 4 or the S3. The Tab 3 connects fine with 4.1.2. The problem seems to occur in the AcceptThread while trying to initialize the BluetoothSocket . The code I'm using is based off of the chat example in the sdk. My Accept code private class AcceptThread extends Thread { // The local server socket private BluetoothServerSocket mmServerSocket; public boolean successInit = false; public AcceptThread() { closeAllConnections(); BluetoothServerSocket tmp

Connecting to a already paired Bluetooth device

北慕城南 提交于 2019-11-30 05:57:15
Recently I tried to get a pairing process to work programatically and I succeded. But I recently found out that the users of my application can be connected to several of "interesting" devices. So I have to prompt the user to choose a device to connect to So I have to connect the user to a already paired bluetooth device. But none of my efforts work. I tried running the pairing process again using the: tmp = device.createRfcommSocketToServiceRecord(MY_UUID); and also the following: Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); mmSocket =

Communication between BLE device and different android apps on same device

六眼飞鱼酱① 提交于 2019-11-30 05:34:23
问题 I'm new in Android BLE so my question may be uncorrect or naive in some way. If this is the case please explain me where I'm wrong and kindly show me the correct way to manage this scenario. Scenario is the following: my Android app communicates with a BLE device sending commands and getting answers from device using BLE characteristics. Sequence is: Device wakes up the app (the onConnectionStateChange method is called) My app writes a command in a characteristic (I call writeCharacteristic