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 7850713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:57:11+00:00 2026-06-02T18:57:11+00:00

I am doing a bluetooth project in which I want to pair two bluetooth

  • 0

I am doing a bluetooth project in which I want to pair two bluetooth devices programmatically in Android. I am using default api in Android. It is finding devices. But does not return Action_found intent. While checking the condition for the action_found intent, it returns false. But in logcat it shows the found devices address. Here is the sample code I tried.

package com.qburst.android.settingsmanager.view;

import java.util.ArrayList;
import java.util.Set;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Toast;

public class Bluetooth extends Activity {
    protected static final int REQUEST_ENABLE_BT = 1;
    private View mBluetooth;
    private Button mOnButton;
    private Button mActiveDevices;
    private Button mDiscoverable;
     public ArrayAdapter<String> mArrayAdapter;
     public BluetoothAdapter mBluetoothAdapter;
     ArrayList<String> devices = new ArrayList<String>();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    setContentView(R.layout.bluetooth);
    mOnButton = (Button) findViewById(R.id.on_button);
    mActiveDevices = (Button) findViewById(R.id.active_devices);
    mDiscoverable = (Button) findViewById(R.id.discoverable_button);
    mArrayAdapter = new ArrayAdapter<String>(this, R.layout.main);
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    registerReceiver(mReceiver, filter);


    mOnButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
              mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
              if (mBluetoothAdapter == null) {
                  // Device does not support Bluetooth
              }
              if (!mBluetoothAdapter.isEnabled()) {
                    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
                }
        }
    });


    mActiveDevices.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

             Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
             System.out.println("checking paired devices");
          // If there are paired devices
          if (pairedDevices.size() > 0) {
              System.out.println(" paired devices");
              // Loop through paired devices
              for (BluetoothDevice device : pairedDevices) {
                  // Add the name and address to an array adapter to show in a ListView
                  mArrayAdapter.add(device.getName() + "\n" + device.getAddress());

              }
          }else {
              mBluetoothAdapter.startDiscovery();
          }
        }
    });

    mDiscoverable.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
             Intent discoverableIntent = new
                     Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
                     discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
                     startActivity(discoverableIntent);
          }
    });
    }

     public void onActivityResult(int requestCode, int resultCode, Intent data) {

            switch (requestCode) {


            case REQUEST_ENABLE_BT:
                // When the request to enable Bluetooth returns
                if (resultCode == Activity.RESULT_OK) {
                    Toast.makeText(this, "Bluetooth enebled", Toast.LENGTH_SHORT).show();

                } else {
                    // User did not enable Bluetooth or an error occurred

                    Toast.makeText(this, "Bluetooth not enebled", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        }


     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                devices.add(device.getName());
                   devices.add(device.getAddress());
                   System.out.println(devices);
                // When discovery finds a device
                Log.i("receiver","Inside receiver");

                if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    System.out.println("device found");
                    Toast.makeText(getBaseContext(), "No device found",Toast.LENGTH_LONG);
                    // Get the BluetoothDevice object from the Intent
                    //BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    // Add the name and address to an array adapter to show in a ListView
                   System.out.println(device.getName());
                   devices.add(device.getName());
                   devices.add(device.getAddress());
                   mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                   System.out.println(devices);
                }
            }
        };


        // Register the BroadcastReceiver

        // Don't forget to unregister during onDestroy
        @Override
        protected void onDestroy() {

            super.onDestroy();
        }
}
  • 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-06-02T18:57:13+00:00Added an answer on June 2, 2026 at 6:57 pm

    You should add the correct action to mReceiver’s filter!
    You should have added: filter.addAction(BluetoothDevice.ACTION_FOUND);

    BluetoothDevice.ACTION_FOUND is not in the filter, so it is never received!

    So change these lines:

    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    registerReceiver(mReceiver, filter);
    

    to this:

    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, filter);
    

    Let me know if it worked!

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

Sidebar

Related Questions

I am doing a project on connection of multiple Android mobiles via Bluetooth. Is
I saw that programmatically turning bluetooth on and off was a private api thing
I have to implement multiplayer game in which I am doing p2p communication using
Doing some client-side JavaScript development, which requires me to call a client-side API which
doing the first Project Euler question: summing the multiples of 3 and 5 between
Doing some project clean up, and rather than just relying on my human eyes
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
I am developing an application which uses Bluetooth to connect to a device and
I need to connect my android to a bluetooth device. I use the BluetoothChat

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.