Encontrando UUIDs no Android 2.0
Estou escrevendo um programa que precisa ser executado no Android 2.0. No momento, estou tentando conectar meu dispositivo Android a um chip Bluetooth integrado. Recebi informações para usar fetchuidsWithSDP () ou getUuids (), mas a página que li explicou que esses métodos estão ocultos no 2.0 SDK e devem ser chamados usando reflexão. Não faço ideia do que isso significa e não há explicação. Há um código de exemplo dado, mas muito pouca explicação por trás dele. Eu estava esperando que alguém pudesse me ajudar a entender o que realmente está acontecendo aqui, já que sou muito novo no desenvolvimento do Android.
String action = "android.bleutooth.device.action.UUID";
IntentFilter filter = new IntentFilter( action );
registerReceiver( mReceiver, filter );
A página que eu leio também diz que na primeira linha o bluetooth é soletrado "bleutooth" de propósito. Se alguém puder explicar isso, eu apreciaria isso, assim como não faz sentido para mim, a menos que os desenvolvedores tenham cometido um erro de digitação.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive( Context context, Intent intent ) {
BluetoothDevice deviceExtra = intent.getParcelableExtra("android.bluetooth.device.extra.Device");
Parcelable[] uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
}
};
Estou com problemas para entender como exatamente encontro o UUID correto para meu chip bluetooth incorporado. Se alguém pudesse ajudar, seria muito apreciado.
EDIT: Eu vou adicionar o resto do meu método onCreate () para que você possa ver o que eu estou trabalhando.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up window View
setContentView(R.layout.main);
// Initialize the button to scan for other devices.
btnScanDevice = (Button) findViewById( R.id.scandevice );
// Initialize the TextView which displays the current state of the bluetooth
stateBluetooth = (TextView) findViewById( R.id.bluetoothstate );
startBluetooth();
// Initialize the ListView of the nearby bluetooth devices which are found.
listDevicesFound = (ListView) findViewById( R.id.devicesfound );
btArrayAdapter = new ArrayAdapter<String>( AndroidBluetooth.this,
android.R.layout.simple_list_item_1 );
listDevicesFound.setAdapter( btArrayAdapter );
CheckBlueToothState();
// Add an OnClickListener to the scan button.
btnScanDevice.setOnClickListener( btnScanDeviceOnClickListener );
// Register an ActionFound Receiver to the bluetooth device for ACTION_FOUND
registerReceiver( ActionFoundReceiver, new IntentFilter( BluetoothDevice.ACTION_FOUND ) );
// Add an item click listener to the ListView
listDevicesFound.setOnItemClickListener( new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
// Save the device the user chose.
myBtDevice = btDevicesFound.get( arg2 );
// Open a socket to connect to the device chosen.
try {
btSocket = myBtDevice.createRfcommSocketToServiceRecord( MY_UUID );
} catch ( IOException e ) {
Log.e( "Bluetooth Socket", "Bluetooth not available, or insufficient permissions" );
} catch ( NullPointerException e ) {
Log.e( "Bluetooth Socket", "Null Pointer One" );
}
// Cancel the discovery process to save battery.
myBtAdapter.cancelDiscovery();
// Update the current state of the Bluetooth.
CheckBlueToothState();
// Attempt to connect the socket to the bluetooth device.
try {
btSocket.connect();
// Open I/O streams so the device can send/receive data.
iStream = btSocket.getInputStream();
oStream = btSocket.getOutputStream();
} catch ( IOException e ) {
Log.e( "Bluetooth Socket", "IO Exception" );
} catch ( NullPointerException e ) {
Log.e( "Bluetooth Socket", "Null Pointer Two" );
}
}
});
}