android bluetooth discovery not finding devicesIs there a way to run Python on Android?How do save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Android SDK installation doesn't find JDKProper use cases for Android UserManager.isUserAGoat()?android: Bluetooth won't discover devices

Do sorcerers' Subtle Spells require a skill check to be unseen?

How does Loki do this?

Can the discrete variable be a negative number?

How does buying out courses with grant money work?

How did Doctor Strange see the winning outcome in Avengers: Infinity War?

Crossing the line between justified force and brutality

How do I rename a Linux host without needing to reboot for the rename to take effect?

Pre-amplifier input protection

Sort a list by elements of another list

Energy of the particles in the particle accelerator

Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?

Term for the "extreme-extension" version of a straw man fallacy?

Was Spock the First Vulcan in Starfleet?

System.debug(JSON.Serialize(o)) Not longer shows full string

Method to test if a number is a perfect power?

Is HostGator storing my password in plaintext?

Return the Closest Prime Number

What is the opposite of 'gravitas'?

Why escape if the_content isnt?

Why does indent disappear in lists?

How do we know the LHC results are robust?

How to Reset Passwords on Multiple Websites Easily?

Avoiding estate tax by giving multiple gifts

Opposite of a diet



android bluetooth discovery not finding devices


Is there a way to run Python on Android?How do save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Android SDK installation doesn't find JDKProper use cases for Android UserManager.isUserAGoat()?android: Bluetooth won't discover devices













1















I have a very simple activity for discovering other android devices via bluetooth:



public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);

// Get the local Bluetooth adapter
FrameLayout f = new FrameLayout(this);
setContentView(f);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

this.registerReceiver(mReceiver, filter);
// Register for broadcasts when discovery has finished
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
this.registerReceiver(mReceiver, filter);

mBtAdapter = BluetoothAdapter.getDefaultAdapter();

// Get a set of currently paired devices
Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();


// Request discover from BluetoothAdapter
Log.i("bluetooth", "about to start device discovery");
mBtAdapter.startDiscovery();

//start receiving stuff
mReceiver = new BluetoothReceiver();




The problem is that the BluetoothRecieiver class called at the end of the activity's onCreate() doesn't seem to find and devices, although I have one turned on in the vicinity when I am debugging this:



 public class BluetoothReceiver extends BroadcastReceiver 
public ArrayAdapter<String> mNewDevicesArrayAdapter;
@Override
public void onReceive(Context context, Intent intent)
String action = intent.getAction();

// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action))
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already paired, skip it, because it's been listed already
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
Log.i("face", device.getName() + "n" + device.getAddress());
mNewDevicesArrayAdapter.add(device.getName() + "n" + device.getAddress());

// When discovery is finished, change the Activity title
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))

if (mNewDevicesArrayAdapter.getCount() == 0)
Log.i("face", "found NOTHING!");
mNewDevicesArrayAdapter.add("no devices found");






Is there anything I am missing here?










share|improve this question




























    1















    I have a very simple activity for discovering other android devices via bluetooth:



    public void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);

    // Get the local Bluetooth adapter
    FrameLayout f = new FrameLayout(this);
    setContentView(f);
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

    this.registerReceiver(mReceiver, filter);
    // Register for broadcasts when discovery has finished
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    this.registerReceiver(mReceiver, filter);

    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    // Get a set of currently paired devices
    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();


    // Request discover from BluetoothAdapter
    Log.i("bluetooth", "about to start device discovery");
    mBtAdapter.startDiscovery();

    //start receiving stuff
    mReceiver = new BluetoothReceiver();




    The problem is that the BluetoothRecieiver class called at the end of the activity's onCreate() doesn't seem to find and devices, although I have one turned on in the vicinity when I am debugging this:



     public class BluetoothReceiver extends BroadcastReceiver 
    public ArrayAdapter<String> mNewDevicesArrayAdapter;
    @Override
    public void onReceive(Context context, Intent intent)
    String action = intent.getAction();

    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action))
    // Get the BluetoothDevice object from the Intent
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    // If it's already paired, skip it, because it's been listed already
    if (device.getBondState() != BluetoothDevice.BOND_BONDED)
    Log.i("face", device.getName() + "n" + device.getAddress());
    mNewDevicesArrayAdapter.add(device.getName() + "n" + device.getAddress());

    // When discovery is finished, change the Activity title
    else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))

    if (mNewDevicesArrayAdapter.getCount() == 0)
    Log.i("face", "found NOTHING!");
    mNewDevicesArrayAdapter.add("no devices found");






    Is there anything I am missing here?










    share|improve this question


























      1












      1








      1








      I have a very simple activity for discovering other android devices via bluetooth:



      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);

      // Get the local Bluetooth adapter
      FrameLayout f = new FrameLayout(this);
      setContentView(f);
      IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

      this.registerReceiver(mReceiver, filter);
      // Register for broadcasts when discovery has finished
      filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
      this.registerReceiver(mReceiver, filter);

      mBtAdapter = BluetoothAdapter.getDefaultAdapter();

      // Get a set of currently paired devices
      Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();


      // Request discover from BluetoothAdapter
      Log.i("bluetooth", "about to start device discovery");
      mBtAdapter.startDiscovery();

      //start receiving stuff
      mReceiver = new BluetoothReceiver();




      The problem is that the BluetoothRecieiver class called at the end of the activity's onCreate() doesn't seem to find and devices, although I have one turned on in the vicinity when I am debugging this:



       public class BluetoothReceiver extends BroadcastReceiver 
      public ArrayAdapter<String> mNewDevicesArrayAdapter;
      @Override
      public void onReceive(Context context, Intent intent)
      String action = intent.getAction();

      // When discovery finds a device
      if (BluetoothDevice.ACTION_FOUND.equals(action))
      // Get the BluetoothDevice object from the Intent
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
      // If it's already paired, skip it, because it's been listed already
      if (device.getBondState() != BluetoothDevice.BOND_BONDED)
      Log.i("face", device.getName() + "n" + device.getAddress());
      mNewDevicesArrayAdapter.add(device.getName() + "n" + device.getAddress());

      // When discovery is finished, change the Activity title
      else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))

      if (mNewDevicesArrayAdapter.getCount() == 0)
      Log.i("face", "found NOTHING!");
      mNewDevicesArrayAdapter.add("no devices found");






      Is there anything I am missing here?










      share|improve this question
















      I have a very simple activity for discovering other android devices via bluetooth:



      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);

      // Get the local Bluetooth adapter
      FrameLayout f = new FrameLayout(this);
      setContentView(f);
      IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

      this.registerReceiver(mReceiver, filter);
      // Register for broadcasts when discovery has finished
      filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
      this.registerReceiver(mReceiver, filter);

      mBtAdapter = BluetoothAdapter.getDefaultAdapter();

      // Get a set of currently paired devices
      Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();


      // Request discover from BluetoothAdapter
      Log.i("bluetooth", "about to start device discovery");
      mBtAdapter.startDiscovery();

      //start receiving stuff
      mReceiver = new BluetoothReceiver();




      The problem is that the BluetoothRecieiver class called at the end of the activity's onCreate() doesn't seem to find and devices, although I have one turned on in the vicinity when I am debugging this:



       public class BluetoothReceiver extends BroadcastReceiver 
      public ArrayAdapter<String> mNewDevicesArrayAdapter;
      @Override
      public void onReceive(Context context, Intent intent)
      String action = intent.getAction();

      // When discovery finds a device
      if (BluetoothDevice.ACTION_FOUND.equals(action))
      // Get the BluetoothDevice object from the Intent
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
      // If it's already paired, skip it, because it's been listed already
      if (device.getBondState() != BluetoothDevice.BOND_BONDED)
      Log.i("face", device.getName() + "n" + device.getAddress());
      mNewDevicesArrayAdapter.add(device.getName() + "n" + device.getAddress());

      // When discovery is finished, change the Activity title
      else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))

      if (mNewDevicesArrayAdapter.getCount() == 0)
      Log.i("face", "found NOTHING!");
      mNewDevicesArrayAdapter.add("no devices found");






      Is there anything I am missing here?







      java android bluetooth






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 5 '16 at 17:23









      Willi Mentzel

      10.5k114971




      10.5k114971










      asked Jul 3 '13 at 14:19









      user1595537user1595537

      1015




      1015






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I think it's because when you call registerReceiver() mReceiver is null, move mReceiver = new BluetoothReceiver(); above the first this.registerReceiver(mReceiver, filter);, also you could do something like



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


          and then call this.registerReceiver(mReceiver, filter); only one time






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17450548%2fandroid-bluetooth-discovery-not-finding-devices%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I think it's because when you call registerReceiver() mReceiver is null, move mReceiver = new BluetoothReceiver(); above the first this.registerReceiver(mReceiver, filter);, also you could do something like



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


            and then call this.registerReceiver(mReceiver, filter); only one time






            share|improve this answer





























              0














              I think it's because when you call registerReceiver() mReceiver is null, move mReceiver = new BluetoothReceiver(); above the first this.registerReceiver(mReceiver, filter);, also you could do something like



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


              and then call this.registerReceiver(mReceiver, filter); only one time






              share|improve this answer



























                0












                0








                0







                I think it's because when you call registerReceiver() mReceiver is null, move mReceiver = new BluetoothReceiver(); above the first this.registerReceiver(mReceiver, filter);, also you could do something like



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


                and then call this.registerReceiver(mReceiver, filter); only one time






                share|improve this answer















                I think it's because when you call registerReceiver() mReceiver is null, move mReceiver = new BluetoothReceiver(); above the first this.registerReceiver(mReceiver, filter);, also you could do something like



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


                and then call this.registerReceiver(mReceiver, filter); only one time







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 8 at 11:34









                Faysal Ahmed

                4,30651534




                4,30651534










                answered Jul 3 '13 at 14:44









                CampigCampig

                10117




                10117





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17450548%2fandroid-bluetooth-discovery-not-finding-devices%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived