In the Samsung galaxy note 3, I have paired a bluetooth device. It is 
paired sucessfully.

In my app I simply run this code in a thread to look for the bluetooth 
device I am interested in and connect automatically to it.

Usually everything works well. But occasionally I will get an unwanted 
Bluetooth Pairing request dialog popup. When this happened, I went to the 
bluetooth settings and I can see the state is "pairing". My question is why 
does an already paired device go into pairing again? And what can I do to 
stop this from happening or get rid of that dialog? I don't want the user 
to have to confirm to anything.


private void open() throws IOException {
>    close();
>    try {    
>      if (android.os.Build.VERSION.SDK_INT >= 
> android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
>        mSocket = mDevice.createInsecureRfcommSocketToServiceRecord(
> SPP_UUID);
>      } else {
>        mSocket = mDevice.createRfcommSocketToServiceRecord(SPP_UUID);
>      }
>      mSocket.connect();
>      mIn = new DataInputStream(mSocket.getInputStream());
>      mOut = new DataOutputStream(mSocket.getOutputStream());
>    } catch (IOException ex) {
>     close();
>     throw ex;
>    }
> }



        public void run() {

            BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

            int sleepDelay;

            while(mFlag) {

                sleepDelay = BLUETOOTH_RETRY_DISCOVERY_TIME;

                Log.e(TAG, "discovering scanner");  

                if(adapter.isEnabled()) {

                    Set<BluetoothDevice> pairedDevices = 
adapter.getBondedDevices();

                    if (pairedDevices.size() > 0) {

                        for (BluetoothDevice device : pairedDevices) {    

                            if(device.getName().startsWith("MY")) {

                                mPairedDevice = device.getName();

                                sleepDelay = BLUETOOTH_RETRY_CONNECTION_TIME
;

                                mDevice = device;

                                if(adapter.isDiscovering()) {

                                    adapter.cancelDiscovery();

                                }

                                try {                               

                                open();

                                 

                                Log.e(TAG, "found bluetooth device and 
connected ok");

                                  

                                    // make sure this is the last thing to 
be done no more scanner interaction after this

                                    synchronized(mConnectThread) {

                                        mConnectThread = null;

                                    }

                                    return;                                

                                } catch (Exception e) {

                                    
notifyUIIfNecessary(getContext().getResources().getString(R.string.
bluetoothscanner_turnon2));

                                    closeConnection();

                                }

                            }

                        }

                    } else {

                        mPairedDevice = "";

                        
notifyUIIfNecessary(getContext().getResources().getString(R.string.
bluetoothscanner_notpaired));

                    }

                } else {

                    
notifyUIIfNecessary(getContext().getResources().getString(R.string.
bluetoothscanner_adapterdisabled));

                }

                try {

                    sleep(sleepDelay);

                } catch (InterruptedException e) {

                }

            }

        }

    }

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/7cc14962-3c92-4f9b-b2f3-fd5fab9aaa6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to