Page 43 - MDP2020-2
P. 43

················································································  명장양성프로젝트  【MDP】  과제발표회  자료집  Ⅱ    |  37



                                            setup();
                                    }
                            }
                    }


                    public  void  setup()  {
                            Button  btnEat  =  findViewById(R.id.btnEat);
                            Button  btnSend  =  findViewById(R.id.btnSend);  //데이터  전송
                            btnSend.setOnClickListener(new  View.OnClickListener()  {
                                    public  void  onClick(View  v)  {
                                            bt.send("Text",  true);
                                    }
                            });
                            btnEat.setOnClickListener(new  View.OnClickListener(){
                                    @Override
                                    public  void  onClick(View  view)  {
                                            bt.send("1",true);
                                    }
                            });
                    }


                    public  void  onActivityResult(int  requestCode,  int  resultCode,  Intent  data)  {
                            if  (requestCode  ==  BluetoothState.REQUEST_CONNECT_DEVICE)  {
                                    if  (resultCode  ==  Activity.RESULT_OK)
                                            bt.connect(data);
                            }  else  if  (requestCode  ==  BluetoothState.REQUEST_ENABLE_BT)  {

                                    if  (resultCode  ==  Activity.RESULT_OK)  {
                                            bt.setupService();
                                            bt.startService(BluetoothState.DEVICE_ANDROID);
                                            setup();
                                    }  else  {
                                            Toast.makeText(getApplicationContext()
                                                            ,  "Bluetooth  was  not  enabled."
                                                            ,  Toast.LENGTH_SHORT).show();
                                            finish();
                                    }
                            }
                            super.onActivityResult(requestCode,  resultCode,  data);
                    }
            }
   38   39   40   41   42   43   44   45   46   47   48