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

  • SEARCH
  • Home
  • 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 7685891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:21:13+00:00 2026-05-31T19:21:13+00:00

When discovering other bluetooth devices I get 2 broadcasts sent for each device found.

  • 0

When discovering other bluetooth devices I get 2 broadcasts sent for each device found. The first is sent during scan and when finishing scan a broadcast is sent for all found device at once. I am adapting the BluetoothChat sample in the SDK.

Here is my ‘BroadcastReceiver’:

 private final BroadcastReceiver foundRec = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(BluetoothDevice.ACTION_FOUND)) {

            Log.e(TAG, "--- device found ---");

            BluetoothDevice dev = intent
                    .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            if (dev.getBondState() == BluetoothDevice.BOND_BONDED) {
                availableDevices.add(dev.getName() + " (paired)");
            } else {
                availableDevices.add(dev.getName());
            }

        } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)){

            Log.d(TAG, "DISCOVERY STARTED");
            findViewById(R.id.lookup).setVisibility(View.VISIBLE);

        }
    }
};

Thank you!

  • 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-31T19:21:14+00:00Added an answer on May 31, 2026 at 7:21 pm

    I keep an array of devices. Every time ACTION_FOUND is received I go through the device array to check if it’s present. My syntax might not be right, typed in browser… but hopefully u get the idea.

    I don’t know what you use your availableDevices array for but it might be more useful if you a BluetoothDevice array instead of String array. You can always get the name and check for bonded state outside of onReceive.

    private final BroadcastReceiver foundRec = new BroadcastReceiver() {
    List<BluetoothDevice> BtDevices = new ArrayList<BluetoothDevice>();
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(BluetoothDevice.ACTION_FOUND)) {
    
            Log.e(TAG, "--- device found ---");
    
            BluetoothDevice dev = intent
                    .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if(!IsBtDevPresent(dev)) {
                BtDevices.add(dev);
                if (dev.getBondState() == BluetoothDevice.BOND_BONDED) {
                    availableDevices.add(dev.getName() + " (paired)");
                } else {
                    availableDevices.add(dev.getName());
                }
            }
        } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)){
    
            Log.d(TAG, "DISCOVERY STARTED");
            findViewById(R.id.lookup).setVisibility(View.VISIBLE);
    
        }
    }
    
    private boolean IsBtDevPresent(BluetoothDevice dev) {
        int size = BtDevices.size();
        for(int i = 0; i<size; i++) {
             if( BtDevices.get(i).equals(dev)) {
                 return true;
             }
        }
        return false;
    }
    

    };

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

Sidebar

Related Questions

After discovering lambda expressions, and their use as anonymous functions, I've found myself writing
After discovering the Boost preprocessor's capabilities I found myself wondering: Is the C99 preprocessor
I've been discovering Ruby on Rails during the last 3 months and I'm fascinated.
Updated 10/21: Changed title and question in order to possibly get an answer (other
After discovering on superuser that there is no current way to add syntax highlighting
I'm discovering a simple solution for singular-plural keywords searches. I heard about stemming but
I'm having trouble discovering exactly what I need to implement in order to use
After recently discovering how insanely long the .net 3.5 framework was to install I
I posted a question last night about Java Reflection and am discovering compiler warnings
I am just learning how to use Terracotta after discovering it about a month

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.