S
Schütz12
Neues Mitglied
- 0
Hallo!
Ich probiere nun schon seit Tagen die Bluetooth Verbindung zu programmieren.
ERFOLGLOS
Das Bluetooth einschalten funktioniert zwar nur ich finde keine anderen Geräte bzw. es zeigt keines an.
Hier das Programm:
MY_UUID = UUID.randomUUID();
//Bluetoth einschalten
if (bluetoothAdapter == null) {
// Device does not support Bluetooth!
return;
}else{
if( !bluetoothAdapter.isEnabled() ) {
// start an activity - ask for enabling Bluetooth
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
begin.setText("Bluetooth enable");
}
}
registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
// Create a BroadcastReceiver for ACTION_FOUND
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
begin.setText("search for Devices");
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
begin.setText("Found Devices");
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
//.add(device.getName() + "\n" + device.getAddress());
setContentView(R.layout.devices);
listDevicesFound = (ListView)findViewById(R.id.list);
listAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1);
listDevicesFound.setAdapter(listAdapter);
listAdapter.add(device.getName() + "\n" + device.getAddress());
}
}
};
bluetoothAdapter.startDiscovery();
Könnt ihr Bitte das Programm durchgehen und mir dann sagen was Falsch ist oder etwas fehlt, wäre echt nett
Danke
Ich probiere nun schon seit Tagen die Bluetooth Verbindung zu programmieren.
ERFOLGLOS

Das Bluetooth einschalten funktioniert zwar nur ich finde keine anderen Geräte bzw. es zeigt keines an.
Hier das Programm:
MY_UUID = UUID.randomUUID();
//Bluetoth einschalten
if (bluetoothAdapter == null) {
// Device does not support Bluetooth!
return;
}else{
if( !bluetoothAdapter.isEnabled() ) {
// start an activity - ask for enabling Bluetooth
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
begin.setText("Bluetooth enable");
}
}
registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
// Create a BroadcastReceiver for ACTION_FOUND
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
begin.setText("search for Devices");
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
begin.setText("Found Devices");
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
//.add(device.getName() + "\n" + device.getAddress());
setContentView(R.layout.devices);
listDevicesFound = (ListView)findViewById(R.id.list);
listAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1);
listDevicesFound.setAdapter(listAdapter);
listAdapter.add(device.getName() + "\n" + device.getAddress());
}
}
};
bluetoothAdapter.startDiscovery();
Könnt ihr Bitte das Programm durchgehen und mir dann sagen was Falsch ist oder etwas fehlt, wäre echt nett
Danke