Home > Mobile > Bluetooth development has search and obtain needed to connect bluetooth address why don't conne
Bluetooth development has search and obtain needed to connect bluetooth address why don't conne
Time:09-17
Already finished to bluetooth search, and by clicking on the ListView can display the search to the equipment needed to click select devices will address displayed in the textview, and then passed on address start connection device, the results did not respond? A great god please help see
//connected bluetooth devices BtConnect=the findViewById (R.i db t_connect); BtConnect. SetOnClickListener (new View. An OnClickListener () { @ Override Public void onClick (View View) { String MAcaddress=tvaddress. GetText (). The toString (); ConnectDevice (MAcaddress); Toast. MakeText (MainActivity. This "connected bluetooth devices." , Toast.LENGTH_SHORT).show(); } });
//bluetooth connection Private void connectDevice (String address) { //determine whether in the search, if in the search, to cancel the search Try {//get the remote device BluetoothDevice nwdevice=bluetoothAdapter. GetRemoteDevice (address); //connection //mSocket=(BluetoothSocket) nwdevice. GetClass () getMethod (" createRfcommSocket ", new Class [] {int. Class}), invoke (nwdevice, 1); MSocket=nwdevice. CreateInsecureRfcommSocketToServiceRecord (MY_UUID); } the catch (IOException e) { e.printStackTrace(); } }
CodePudding user response:
Even not, see the error message
CodePudding user response:
Why use reflection to connect, the normal use function call