Unsecured Android Bluetooth connection

I was challenged by a professor to develop a small application to demonstrate Bluetooth on Android. I knew nothing about Android development until 2 weeks ago when he gave me this task. I am also completely new to Java programming in general, so I'm starting far. But anyway...

So, I did most of the tutorial, and I read about Bluetooth in Android, looked at the bluetooth chat code sample, and now I'm trying to make my own small application. Therefore, for my demonstration, I will try to establish a connection between my real phone and my Bluetooth mouse. I want to move a piece on the screen of my phone in response to my mouse movement.

I have many problems, but still the main way is to open the socket with my unprotected mouse. When I try to use the listenUsingRfcommWithServiceRecord method, it asks for the UUID as a parameter. But my mouse most likely does not have a UUID response, so I assume this method is not good.

When I read the documentation about this method, it says that to open an insecure server socket using a device such as a mouse, I have to use the listenUsingInsecureRfcommWithServiceRecord method. But this method is not available when I call it, it is underlined in red, and Eclipse says that it is undefined for the type BluetoothAdapter.

 private BluetoothServerSocket connectDevice(BluetoothAdapter adapter, BluetoothDevice device){ BluetoothServerSocket socket = null; try{ socket = adapter.listenUsingInsecureRfcommWithServiceRecord(device.getName(), UUID.randomUUID()); } catch(IOException e){ Toast.makeText(this, "Connection failed.\n" + e.getMessage(), Toast.LENGTH_SHORT); } return socket; } 

Please do not cry if I do it all wrong, this is my first question here, and I start with Java programming.

+4
source share
3 answers
 listenUsingInsecureRfcommWithServiceRecord() 

This is only available at API level 10 and later, i.e. Android version 2.3.3 onwards.

This can be a problem if you create a version prior to this.

See the right side of the gray panel in docs

EDIT: Since the BluetoothAdapter extension is not possible, listenUsingInsecureRfcommWithServiceRecord() just does it ...

 return createNewRfcommSocketAndRecord(name, uuid, false, false); 

The source for createNewRfcommSocketAndRecord () (which is a private BluetoothAdapter method) can be found here ... createNewRfcommSocketAndRecord

Not sure what will help, but you can reproduce its functionality.

+3
source

If you are trying to talk with a commercial mouse, then using the SPP socket APIs in android will not help, the mouse uses a Bluetooth HID profile, and this requires the phone to have a HID profile host role. The standard Android release does not support HID at present - so you have to add it yourself and build an android that integrates the HID from BlueZ and connects it to your application.

0
source

To support the Bluetooth profile that will be implemented on Android, there is a project called "Sybase-iAnywhere-Blue-SDK for Android", which replaces the Android version and provides all the interfaces in the basic profiles and protocols of Bluetooth. Using this, printing via Bluetooth using an Android phone will be possible using the BPP profile provided by this SDK.

See the links below for more details: link 1: http://www.sybase.com/detail?id=1064424

Link 2: http://www.sybase.com/products/allproductsa-z/mobiledevicesdks/bluetoothsdks

-1
source

Source: https://habr.com/ru/post/1347379/


All Articles