Encontrar UUIDs en Android 2.0
Estoy escribiendo un programa que debe ejecutarse en Android 2.0. Actualmente estoy tratando de conectar mi dispositivo Android a un chip Bluetooth integrado. Se me ha dado información para usar fetchuidsWithSDP () o getUuids (), pero la página que leí explica que estos métodos están ocultos en el SDK 2.0 y deben llamarse utilizando la reflexión. No tengo idea de lo que eso significa y no hay explicación. Hay un código de ejemplo dado, pero muy poca explicación detrás de él. Esperaba que alguien pudiera ayudarme a entender lo que realmente está sucediendo aquí, ya que soy muy nuevo en el desarrollo de Android.
String action = "android.bleutooth.device.action.UUID";
IntentFilter filter = new IntentFilter( action );
registerReceiver( mReceiver, filter );
La página que leí también dice que en la primera línea se escribe bluetooth "bleutooth" a propósito. Si alguien puede explicarlo, lo apreciaría tan bien como no tiene sentido para mí, a menos que los desarrolladores hayan cometido un error tipográfico.
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");
}
};
Estoy teniendo problemas para entender exactamente cómo encuentro el UUID correcto para mi chip Bluetooth incrustado. Si alguien pudiera ayudar sería muy apreciado.
EDITAR: Agregaré el resto de mi método onCreate () para que pueda ver con qué estoy trabajando.
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" );
}
}
});
}