Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve Bluetooth device info with Android Bluetooth device picker?
    primarykey
    data
    text
    <p>Here is the test code that I am using :</p> <pre><code>public class IOConnectDirect extends Activity { private static final String TAG = "IOConnectDirect"; private static final int REQCODE_BLUETOOTH_RESULT = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate"); setTitle(getTitle() + "--" + TAG); Intent intentBluetooth = new Intent(); intentBluetooth.setAction("android.bluetooth.devicepicker.action.LAUNCH"); //android.bluetooth.devicepicker.action.DEVICE_SELECTED not working . startActivityForResult(intentBluetooth, REQCODE_BLUETOOTH_RESULT); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i(TAG, "onActivityResult(" + requestCode +"," + resultCode + ")"); switch (requestCode) { case REQCODE_BLUETOOTH_RESULT: Log.i(TAG, "requestCode = REQCODE_BLUETOOTH_RESULT"); if(resultCode == RESULT_OK) { Log.i(TAG, "RESULT_OK"); // Retrieve the Info Bundle extras = data.getExtras(); if(extras != null) { Log.i(TAG, "Bundle ok"); } } else { Log.i(TAG, "!RESULT_OK = FAILED(" + resultCode + ")"); Toast.makeText(this, "Failed(" + resultCode +")", Toast.LENGTH_SHORT).show(); } break; default: Log.i(TAG, "requestCode = ????"); break; } } </code></pre> <p>}</p> <p>Here is the Logcat output :</p> <pre><code>I/IOConnectDirect(14956): onActivityResult(0,0) I/IOConnectDirect(14956): requestCode = REQCODE_BLUETOOTH_RESULT I/IOConnectDirect(14956): !RESULT_OK = FAILED(0) </code></pre> <p>The code works (you need to activate Bluetooth first ) , I am just unable to make it do what I want which is to retrieve the Bluetooth device name and address that I selected from the activity .</p> <p>Note :</p> <ul> <li>I am not trying to connect I just want the select device information .</li> <li>I am familiar with other methods to do this like in the Android Bluetooth Chat Sample </li> </ul> <p><strong>UPDATE</strong></p> <p>I end up using a BroadcastReceiver</p> <pre><code>public class IOConnectDirect extends Activity { private static final String TAG = "IOConnectDirect"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate"); BluetoothConnectActivityReceiver mBluetoothPickerReceiver = new BluetoothConnectActivityReceiver(); registerReceiver(mBluetoothPickerReceiver, new IntentFilter(BluetoothDevicePicker.ACTION_DEVICE_SELECTED)); startActivity(new Intent(BluetoothDevicePicker.ACTION_LAUNCH) .putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false) .putExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, BluetoothDevicePicker.FILTER_TYPE_ALL) .setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)); } public class BluetoothConnectActivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(BluetoothDevicePicker.ACTION_DEVICE_SELECTED.equals(intent.getAction())) { context.unregisterReceiver(this); BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); Toast.makeText(context, "device" + device.getAddress(), Toast.LENGTH_SHORT).show(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload