Page 86 - MDP2022-2
P. 86

Toast.LENGTH_SHORT).show();
                            }
                    }



                    void  connectSelectedDevice(String  selectedDeviceName)  {
                            for  (BluetoothDevice  tempDevice  :  mPairedDevices)  {
                                    if  (ActivityCompat.checkSelfPermission(this,  Manifest.permission.BLUETOOT
            H_CONNECT)  !=  PackageManager.PERMISSION_GRANTED)  {
                                            //  TODO:  Consider  calling

                                            //        ActivityCompat#requestPermissions
                                            //  here  to  request  the  missing  permissions,  and  then  overriding
                                            //      public  void  onRequestPermissionsResult(int  requestCode,  String[]  pe
            rmissions,
                                            //                                                                                    int[]  grantResults)
                                            //  to  handle  the  case  where  the  user  grants  the  permission.  See  the  do

            cumentation
                                            //  for  ActivityCompat#requestPermissions  for  more  details.
                                            return;
                                    }

                                    if  (selectedDeviceName.equals(tempDevice.getName()))  {
                                            mBluetoothDevice  =  tempDevice;
                                            Toast.makeText(getApplicationContext(),"연결  됐습니다.",Toast.LENGTH_S
            HORT).show();
                                            break;
                                    }

                            }
                            try  {
                                    mBluetoothSocket  =  mBluetoothDevice.createRfcommSocketToServiceRecord
            (BT_UUID);

                                    mBluetoothSocket.connect();
                                    mThreadConnectedBluetooth  =  new  ConnectedBluetoothThread(mBluetoothSo
            cket);
                                    mThreadConnectedBluetooth.start();
                                    mBluetoothHandler.obtainMessage(BT_CONNECTING_STATUS,  1,  -1).sendTo
            Target();

                            }  catch  (IOException  e)  {
                                    Toast.makeText(getApplicationContext(),  "블루투스  연결  중  오류가  발생했습니
            다.",  Toast.LENGTH_LONG).show();
                            }

                    }
   81   82   83   84   85   86   87   88   89   90   91