Page 85 - MDP2022-2
P. 85

//        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;

                                    }
                                    mPairedDevices  =  mBluetoothAdapter.getBondedDevices();


                                    if  (mPairedDevices.size()  >  0)  {
                                            AlertDialog.Builder  builder  =  new  AlertDialog.Builder(this);
                                            builder.setTitle("장치  선택");



                                            mListPairedDevices  =  new  ArrayList<String>();
                                            for  (BluetoothDevice  device  :  mPairedDevices)  {
                                                    mListPairedDevices.add(device.getName());

                                                    //mListPairedDevices.add(device.getName()  +  "\n"  +  device.getAdd
            ress());
                                            }
                                            final  CharSequence[]  items  =  mListPairedDevices.toArray(new  CharSequ
            ence[mListPairedDevices.size()]);
                                            mListPairedDevices.toArray(new   CharSequence[mListPairedDevices.size

            ()]);


                                            builder.setItems(items,  new  DialogInterface.OnClickListener()  {
                                                    @Override

                                                    public  void  onClick(DialogInterface  dialog,  int  item)  {
                                                            connectSelectedDevice(items[item].toString());
                                                    }
                                            });
                                            AlertDialog  alert  =  builder.create();
                                            alert.show();

                                    }  else  {
                                            Toast.makeText(getApplicationContext(),  "페어링된  장치가  없습니다.",  Toa
            st.LENGTH_LONG).show();
                                    }

                            }  else  {
                                    Toast.makeText(getApplicationContext(),  "블루투스가  비활성화  되어  있습니다.",
   80   81   82   83   84   85   86   87   88   89   90