i'm developing a code which lists all paired devices (working till here) and on click on a device whcih are listed in textviews, i want the programm to connect to device programmatically. So here is myCode:
final View.OnClickListener onclicklistener = new View.OnClickListener() {
@Override
public void onClick(View view) {
index_connection=view.getId();
try {
btSocket=devices[index_connection].createInsecureRfcommSocketToServiceRecord(myUUID);
} catch (IOException e) {
e.printStackTrace();
}
try {
btSocket.connect();
} catch (IOException e) {
try {
btSocket.close();
Toast.makeText(Connection.this, "Connected to "+devices[index_connection].getName(),Toast.LENGTH_LONG);
} catch (IOException e1) {
Toast.makeText(Connection.this, "Not connected!",Toast.LENGTH_LONG);
e1.printStackTrace();
}
}
}
};
So onclick i'm getting the ID of the Textview which is equal with the index of the device i saved into an array. But now on clicking it does not create any connection (and yes, the other device has Bluetooth activated). The code throws an Exception if i'm getting the device UUID from the Telephony manager:
myUUID = UUID.fromString(tManager.getDeviceId());
The exception says: java.lang.SecurityException: getDeviceId: The user 10284 does not meet the requirements to access device identifiers.
If i try to create the UUID "fromString" i don't get an exception, but it doesn't connect either.
Best regars, flar2000