Android - Bluetooth_Hc-05_datos

 
Vista:

Bluetooth_Hc-05_datos

Publicado por Ulises (1 intervención) el 26/03/2016 05:26:00
Buenas noches, tengo un problema lo que quiero es conectarme con un dispositivo Hcc-05, solo ese dispositivo y una ves conectado, quisiera saber como hago para, cunado recibo por ejemplo un 1, se abre una actividad, recibo 2, se abre otra actividad, recibo 3 , se abre otra actividad y así sucesivamente ...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
public class coneccion extends AppCompatActivity
{
 
    private static final int REQUEST_ENABLE_BT = 10;
 
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coneccion);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
 
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
 
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter == null) {
            // El dispositivo no soporta Bluetooth
            Toast.makeText(getApplicationContext(), "El dispositivo no sorporta Bluetooth", Toast.LENGTH_SHORT).show();
        }
 
        if  (! mBluetoothAdapter . isEnabled ())  {
            Intent enableBtIntent =  new  Intent ( BluetoothAdapter . ACTION_REQUEST_ENABLE );
            startActivityForResult ( enableBtIntent , REQUEST_ENABLE_BT );
        }
 
        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// Si hay dispositivos vinculados
        if (pairedDevices.size() > 0) {
            // Bucle a través de dispositivos vinculados
            for (BluetoothDevice device : pairedDevices) {
                // Añadir el nombre y dirección a un adaptador de matriz para mostrar en un ListView
 
 
                AbstractList<String> mArrayAdapter = null;
                mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }
        }
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_coneccion, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
 
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
 
        return super.onOptionsItemSelected(item);
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder