Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7002115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:53:17+00:00 2026-05-27T20:53:17+00:00

Here is the test code that I am using : public class IOConnectDirect extends

  • 0

Here is the test code that I am using :

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;
    }
}

}

Here is the Logcat output :

I/IOConnectDirect(14956): onActivityResult(0,0)
I/IOConnectDirect(14956): requestCode = REQCODE_BLUETOOTH_RESULT
I/IOConnectDirect(14956): !RESULT_OK = FAILED(0)

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 .

Note :

  • I am not trying to connect I just want the select device information .
  • I am familiar with other methods to do this like in the Android Bluetooth Chat Sample

UPDATE

I end up using a BroadcastReceiver

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();
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:53:17+00:00Added an answer on May 27, 2026 at 8:53 pm

    Try this code:

    private final BroadcastReceiver mBluetoothPickerReceiver = new BluetoothConnectActivityReceiver(this);
    
     void connectToService(String defaultAdapter) {
        if (defaultAdapter == null) {
            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));
        } else {
            mCardroid.getCardroidService().connectTo(defaultAdapter);
        }
    }
    
    public class BluetoothConnectActivityReceiver extends BroadcastReceiver {
        private BluetoothConnectActivity bluetoothConnectActivity;
     public BluetoothConnectActivityReceiver(BluetoothConnectActivity bluetoothConnectActivity) {
                this.bluetoothConnectActivity = bluetoothConnectActivity;
            }
    
         @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);
                        bluetoothConnectActivity.connectToService(device.getAddress());
                    }
                }
            }
    

    The reference of complete code is :

    http://code.google.com/p/carbot/source/browse/trunk/src/net/cardroid/?r=8

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, my goal is to test the code given here: PHP script that
I am using Selenium Grid with TestNG to test a website. The test-code, that
I have a code here that generates XML for Engineer list using linq. My
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
I am trying to test some of these code here http://ha.ckers.org/xss.html on my code.
I often hear around here from test driven development people that having a function
Here is a test description, testing the Create New Widget use-case. Confirm that you
I suppose that this is an interesting code example. We have a class --
I'm using the TPL but I'm finding it tricky unit testing code that uses
I have a Web Service(.ASMX) code that takes a String Array as a parameter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.