Поиск UUID в Android 2.0
Я пишу программу, которая должна быть запущена в Android 2.0. В настоящее время я пытаюсь подключить устройство Android к встроенному чипу Bluetooth. Мне дали информацию о том, как использовать fetchuidsWithSDP () или getUuids (), но на странице, которую я прочитал, объяснялось, что эти методы скрыты в 2.0 SDK и должны вызываться с использованием отражения. Я понятия не имею, что это значит, и нет никаких объяснений. Приведен пример кода, но за ним очень мало объяснений. Я надеялся, что кто-нибудь поможет мне понять, что на самом деле здесь происходит, так как я очень новичок в разработке для Android.
String action = "android.bleutooth.device.action.UUID";
IntentFilter filter = new IntentFilter( action );
registerReceiver( mReceiver, filter );
На странице, которую я прочитал, также написано, что в первой строке Bluetooth пишется как «bleutooth». нарочно. Если кто-то может это объяснить, я был бы признателен за это, так как для меня это не имеет смысла, если разработчики не сделали опечатку.
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");
}
};
У меня возникают проблемы с пониманием того, как именно я нахожу правильный UUID для моего встроенного чипа Bluetooth. Если бы кто-то мог помочь, я был бы очень признателен.
РЕДАКТИРОВАТЬ: Я собираюсь добавить остальную часть моего метода onCreate (), чтобы вы могли видеть, с чем я работаю.
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" );
}
}
});
}