Beispiel #1
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.app_connect_button) {
      // Intent intent = new Intent(getBaseContext(), CollectDataActivity.class);
      // startActivity(intent);;
      BluetoothHelper bluetoothHelper = BluetoothHelper.getInstance();
      final HashMap<String, String> pairedDevices = bluetoothHelper.GetPairedDevices();

      if (pairedDevices.isEmpty())
        Toast.makeText(this, "No paired devices found.", Toast.LENGTH_LONG).show();
      else
        SimpleDialogs.ChooseOption(
            this,
            pairedDevices.keySet().toArray(new String[pairedDevices.keySet().size()]),
            new DialogResponse() {
              @Override
              public void onDialogResponse(String deviceName) {
                String deviceAddress = pairedDevices.get(deviceName);
                Toast.makeText(
                        EntranceActivity.this, "Choosed device:" + deviceAddress, Toast.LENGTH_LONG)
                    .show();
                EntranceActivity.this.ConnectDevice(deviceAddress);
              }
            });
    }

    if (v.getId() == R.id.app_last_trips_button) {
      Intent intent = new Intent(getBaseContext(), LastTripsActivity.class);
      startActivity(intent);
    }
  }
Beispiel #2
0
 private void ConnectDevice(String deviceAddress) {
   BluetoothHelper bth = BluetoothHelper.getInstance();
   try {
     bth.ConnectDevice(deviceAddress);
     Intent intent = new Intent(getBaseContext(), CollectDataActivity.class);
     startActivity(intent);
   } catch (IOException e) {
     e.printStackTrace();
     Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
   }
 }