Problem with bluetooth permissions

Hi.
I want to make a test with the bluetooth on my device (the code is not mine, is from here: Android-java-code-utilities-widgets-for-Processing-for-Android/Android Arduino Bluetooth example at master · EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android · GitHub) The problem is that each time I want to run the code, this appears:
FATAL EXCEPTION: Animation Thread
Process: processing.test.sketch_220904e, PID: 8302
java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10015, packageName = processing.test.sketch_220904e, attributionTag = null, token = android.os.BinderProxy@b49afa6, next = null }: AdapterService getBondedDevices
at android.os.Parcel.createExceptionOrNull(Parcel.java:2437)
at android.os.Parcel.createException(Parcel.java:2421)
at android.os.Parcel.readException(Parcel.java:2404)
at android.os.Parcel.readException(Parcel.java:2346)
at android.bluetooth.IBluetooth$Stub$Proxy.getBondedDevices(IBluetooth.java:5168)
at android.bluetooth.BluetoothAdapter.getBondedDevices(BluetoothAdapter.java:3762)
at ketai.net.bluetooth.KetaiBluetooth.getPairedDeviceNames(KetaiBluetooth.java:264)
at processing.test.sketch_220904e.sketch_220904e.setup(sketch_220904e.java:95)
at processing.core.PApplet.handleDraw(PApplet.java:1878)
at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:478)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:518)

Im not sure why this appears, even if I already set the sketch permissions with all the Bluetooth options, and in the settings of my phone it shows that the app has access to all bluetooth commands.

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.*; 
import android.widget.FrameLayout;
import android.widget.LinearLayout; 
import android.graphics.Color;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Gravity;
import android.R;
import ketai.net.bluetooth.*;
import java.lang.reflect.Method;
import android.graphics.Color;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.os.Bundle;
import android.widget.SeekBar; 
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.Paint;
import android.graphics.Typeface;
//import oscP5.*;

String device_name = "HC-05";
//String device_mac = "40:45:DA:00:25:05";
String device_mac = "98d3:34:90f40d";
Activity act; 
Context mC;
FrameLayout fl;
SeekBar seekBar;
KetaiBluetooth bt;
int ts, pgr_r = 150, pgr_g = 150, pgr_b = 200, seekbar_width;
boolean drag;
int button_toggle_value = 2;

void setup() {
  fullScreen();
  orientation(PORTRAIT);
  background(255, 220, 160);
  stroke(140, 90, 35);
  noFill();
  strokeWeight(width/30);
  rect(0, 0, width, height);
  ellipseMode(CENTER);
  textAlign(CENTER, CENTER);
  bt.getPairedDeviceNames();
  bt.start();
  //bt.connectDevice("40:45:DA:00:25:05");
  bt.connectToDeviceByName(device_name);
}

void draw() {
  stroke(pgr_r/1.2, pgr_g/1.2, pgr_b/1.2);
  fill(pgr_r, pgr_g, pgr_b);
  ellipse(width/2, height/4, width/2, width/2);
}

void mouseDragged() {
  drag = true;
}

void mouseReleased () {
  drag = false;
}
void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}

@Override 
  public void onStart() {
  super.onStart();
  act = this.getActivity();
  mC= act.getApplicationContext();
  act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  seekbar_width = width-width/10;

  ShapeDrawable oval = new ShapeDrawable(new OvalShape());
  oval.setIntrinsicHeight (height);
  oval.setIntrinsicWidth (width);
  oval.getPaint().setColor(Color.rgb(150, 100, 35));

  final TextView button = new TextView(act);  
  button.setLayoutParams(new RelativeLayout.LayoutParams(width/6, width/6));
  button.setBackground(oval);
  button.setX(7.4*width/10);
  button.setY(height/30);
  String str = "Test to measure the text size.";
  textSize(12);
  float twf = width/textWidth(str);
  ts = int(3.5*twf);
  button.setText("Dim");
  button.setGravity(Gravity.CENTER);
  button.setTextColor(Color.WHITE);
  button.setTextSize(ts);
  button.setTypeface(null, Typeface.BOLD);
  button.setOnClickListener(new View.OnClickListener() {
    @Override
      public void onClick(View v) {
      button_toggle_value++;
      if (button_toggle_value > 2) button_toggle_value = 0;
      if (button_toggle_value == 0) {
        button.setText("Off");
        pgr_r = 0;
        pgr_g = 0;
        pgr_b = 0;
        String str = "<0,2,"+str(button_toggle_value)+">";
        byte[] data = str.getBytes();
        //bt.write(device_mac, data);
        bt.writeToDeviceName(device_name, data);
      }
      if (button_toggle_value == 1) {
        button.setText("On");
        pgr_r = 255;
        pgr_g = 255;
        pgr_b = 255;
        String str = "<0,2,"+str(button_toggle_value)+">";
        byte[] data = str.getBytes();
        //bt.write(device_mac, data);
        bt.writeToDeviceName(device_name, data);
      }
      if (button_toggle_value == 2) {
        button.setText("Dim");
        pgr_r = 80;
        pgr_g = 80;
        pgr_b = 80;
        for (int i = 0; i < 3; i++) {
          String str = "<80,"+str(i)+","+str(button_toggle_value)+">";
          byte[] data = str.getBytes();
          //bt.write(device_mac, data);
          bt.writeToDeviceName(device_name, data);
        }
      }
    }
  }
  );

  final GradientDrawable red_bar = new GradientDrawable(); 
  red_bar.setColor(Color.rgb(pgr_r, 0, 0));
  red_bar.setStroke(3, Color.BLACK);

  final GradientDrawable green_bar = new GradientDrawable(); 
  green_bar.setColor(Color.rgb(0, pgr_g, 0));
  green_bar.setStroke(3, Color.BLACK);

  final GradientDrawable blue_bar = new GradientDrawable(); 
  blue_bar.setColor(Color.rgb(0, 0, pgr_b));
  blue_bar.setStroke(3, Color.BLACK);

  final TextView redBar = new TextView(act);  
  redBar.setLayoutParams(new RelativeLayout.LayoutParams(seekbar_width, height/20));
  redBar.setBackground(red_bar);
  redBar.setX(width/20);
  redBar.setY(height-height/4.74);

  final TextView greenBar = new TextView(act);  
  greenBar.setLayoutParams(new RelativeLayout.LayoutParams(seekbar_width, height/20));
  greenBar.setBackground(green_bar);
  greenBar.setX(width/20);
  greenBar.setY(height-height/2.76);

  final TextView blueBar = new TextView(act);  
  blueBar.setLayoutParams(new RelativeLayout.LayoutParams(seekbar_width, height/20));
  blueBar.setBackground(blue_bar);
  blueBar.setX(width/20);
  blueBar.setY(height-height/1.96);

  SeekBar seekBar1 = new SeekBar(mC); 
  seekBar1.setLayoutParams (new RelativeLayout.LayoutParams (seekbar_width, height/15));
  seekBar1.setX(width/20);
  seekBar1.setY(height-height/7);
  seekBar1.setMax(250);
  seekBar1.setProgress(pgr_r);
  seekBar1.setBackgroundColor(Color.rgb(230, 200, 140));
  seekBar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
    @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onStopTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onProgressChanged (SeekBar seekBar, final int progress, boolean fromUser) { 
      pgr_r = progress;
      red_bar.setColor(Color.rgb(pgr_r, 0, 0));
      red_bar.setStroke(3, Color.BLACK); 
      redBar.setBackground(red_bar);
      String str = "<"+str(pgr_r)+",0,"+str(button_toggle_value)+">";
      byte[] data = str.getBytes();
      //bt.write(device_mac, data);
      bt.writeToDeviceName(device_name, data);
      //OscMessage m = new OscMessage(str);
      //bt.broadcast(m.getBytes());
    }
  }
  );

  SeekBar seekBar2 = new SeekBar(mC); 
  seekBar2.setLayoutParams (new RelativeLayout.LayoutParams (seekbar_width, height/15));
  seekBar2.setX(width/20);
  seekBar2.setY(height-height/3.4);
  seekBar2.setMax(250);
  seekBar2.setProgress(pgr_g);
  seekBar2.setBackgroundColor(Color.rgb(230, 200, 140));
  seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
    @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onStopTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onProgressChanged (SeekBar seekBar, final int progress, boolean fromUser) { 
      pgr_g = progress;
      green_bar.setColor(Color.rgb(0, pgr_g, 0));
      green_bar.setStroke(3, Color.BLACK); 
      greenBar.setBackground(green_bar);
      String str = "<"+str(pgr_g)+",1,"+str(button_toggle_value)+">";
      byte[] data = str.getBytes();
      //bt.write(device_mac, data);
      bt.writeToDeviceName(device_name, data);
      //OscMessage m = new OscMessage(str);
      //bt.broadcast(m.getBytes());
    }
  }
  );

  SeekBar seekBar3 = new SeekBar(mC); 
  seekBar3.setLayoutParams (new RelativeLayout.LayoutParams (seekbar_width, height/15));
  seekBar3.setX(width/20);
  seekBar3.setY(height-height/2.25);
  seekBar3.setMax(250);
  seekBar3.setProgress(pgr_b);
  seekBar3.setBackgroundColor(Color.rgb(230, 200, 140));
  seekBar3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
    @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onStopTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onProgressChanged (SeekBar seekBar, final int progress, boolean fromUser) { 
      pgr_b = progress;
      blue_bar.setColor(Color.rgb(0, 0, pgr_b));
      blue_bar.setStroke(3, Color.BLACK); 
      blueBar.setBackground(blue_bar);
      String str = "<"+str(pgr_b)+",2,"+str(button_toggle_value)+">";
      byte[] data = str.getBytes();
      //bt.write(device_mac, data);
      bt.writeToDeviceName(device_name, data);
      //OscMessage m = new OscMessage(str);
      //bt.broadcast(m.getBytes());
    }
  }
  );
  fl = (FrameLayout)act.findViewById(R.id.content);
  FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
  fl.addView(redBar);
  fl.addView(greenBar);
  fl.addView(blueBar);
  fl.addView(seekBar1);
  fl.addView(seekBar2);
  fl.addView(seekBar3);
  fl.addView(button);
}

void onPause() {
  bt.stop();
}

void onStop() {
  bt.stop();
}

Is something else I need to declare for making it work?
Any help I would appreciate it so much

As a test, please see if you can run this code:

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import java.util.Set;

String[] devices = {};
 
 void findPairedBluetoothDevices() {
 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
 if (adapter == null) {
    println("Device doesn't support Bluetooth.");
 } else {
   Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
   if (pairedDevices.size() > 0) {
    // Get the name and address of each paired device.
     for (BluetoothDevice device : pairedDevices) {
       String deviceName = device.getName();
       String deviceHardwareAddress = device.getAddress(); // MAC address
       String deviceInfo = deviceName + "\n   " + deviceHardwareAddress;
       devices = append(devices, deviceInfo);
       println(deviceInfo);
     }       
  }
 }
}

void setup() {
  fullScreen();
 // orientation(LANDSCAPE);
  orientation(PORTRAIT);
  findPairedBluetoothDevices();
}

void draw() {
  color BLUE = color(64,124,188);
  background(BLUE);
  fill(255);
  textSize(48);
  for(int j = 0; j < devices.length; j++) {
  text(devices[j], 130, 100 + (180 * j), 500, 180);
  }
}

Sketch Permissions:

permissions

It works without a problem. Each device appears with their MAC adresses

This is some code that I have used in past; see if you can adapt it to your project without too much trouble.

/*
 For use on Android devices.
 Has both in/out streams.
 Rev.2
*/

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import java.util.Set;
import java.util.UUID;
 
// Make sure sketch permissions are set for Bluetooth
// ACCESS_COARSE_LOCATION
// BLUETOOTH
// BLUETOOTH_ADMIN

// DropDownList control => a.)displayFld b.)arrow c.)list
 
BluetoothAdapter bluetoothAdapter = null;

final int _deviceDisplayX =  30;
final int _deviceDisplayY = 60;
final int _deviceDisplayW = 450;
final int _deviceDisplayH = 60;
final int _deviceItemH = 120;
final int _deviceArrwX = _deviceDisplayX + _deviceDisplayW;
final int _deviceArrwY = _deviceDisplayY;
final int _deviceArrwSize = _deviceDisplayH;

final int _connectBtnX = 600;
final int _connectBtnY = 60;
final int _connectBtnW = 250;
final int _connectBtnH = 60;

final int _quitBtnX = 890;
final int _quitBtnY = 60;
final int _quitBtnW = 150;
final int _quitBtnH = 60;

final int _dataDisplayX = 1200;
final int _dataDisplayY = 60;
final int _dataDisplayW = 150;
final int _dataDisplayH = 60;

int value = 0;

boolean deviceListDrop;
boolean connectSelected;

color BLUE = color(64,124,188);
color GREEN = color(0,126,0);

String[] deviceArray = {};
String[] deviceAddress = {};
int[] _deviceItemY;
int selectedDevice = -1;
int numDevices = 0;
int[] dataArray;


Thread runThread;
byte[] readBuffer;
int buffer_index;
int counter;
boolean stop_thread, plotting = false, init = true;

 void findPairedBluetoothDevices() {
 bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
 if (bluetoothAdapter == null) {
    println("Device doesn't support Bluetooth.");
 } else {
   Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
   if (pairedDevices.size() > 0) {
    // Get the name and address of each paired device.
     for (BluetoothDevice device : pairedDevices) {
      // device = append(device,device);
       String deviceName = device.getName();
       String deviceHardwareAddress = device.getAddress(); // MAC address
       deviceAddress = append(deviceAddress, device.getAddress());
       String deviceInfo = deviceName + "\n   " + deviceHardwareAddress;
       deviceArray = append(deviceArray, deviceInfo);
     }       
  }
 }
}

class DeviceDisplay {
  
 void press() {
 // device arrow touches
  if(deviceListDrop){
   deviceListDrop = false;
   } else {
   deviceListDrop = true;
  }
 }
  
 void deviceDisplayString(String str) {
  fill(255); // display field background color
  noStroke();
  rect(_deviceDisplayX,_deviceDisplayY,_deviceDisplayW,_deviceDisplayH);
  fill(0); // text color
  textSize(42);
  text(str, _deviceDisplayX + 10, _deviceDisplayY + 15, _deviceDisplayW, _deviceDisplayH);
}

 void display(){
 // display field
  if(selectedDevice == -1){
   deviceDisplayString("Select device:");   
  } else {
   deviceDisplayString(deviceArray[selectedDevice]); 
  }
 // arrow
  fill(255);
  noStroke();
  rect(_deviceArrwX, _deviceArrwY, _deviceArrwSize, _deviceArrwSize);
  fill(GREEN);
  triangle(_deviceArrwX+5,_deviceArrwY+5,_deviceArrwX+_deviceArrwSize-5,_deviceArrwY+5,_deviceArrwX+_deviceArrwSize/2,_deviceArrwY+_deviceArrwSize-5);
 }
  
}

DeviceDisplay deviceDisplay;

class DeviceList {
 
 void press(float mx, float my){
   // device list touches
   if (deviceArray.length > 0) {
   for(int j = 0; j < deviceArray.length; j++){
    if((mx >= _deviceDisplayX) && (mx <= _deviceDisplayX + _deviceDisplayW) && (my >= _deviceItemY[j] ) && (my <= _deviceItemY[j] + _deviceItemH)) {
     selectedDevice = j;
     deviceListDrop = false;
     // erases list
     fill(BLUE);
     rect(_deviceDisplayX, _deviceDisplayY, _deviceDisplayW, _deviceDisplayY + _deviceDisplayH + deviceArray.length*_deviceItemH);
    } 
   }
  }
 } 
  
 void display(){
  // deviceListItems
  if (deviceListDrop){
   if (deviceArray.length > 0) { 
   _deviceItemY = new int[deviceArray.length];
    for(int j = 0; j < deviceArray.length; j++) {
     _deviceItemY[j] = (_deviceDisplayY + _deviceDisplayH) + j*_deviceItemH;      
     fill(255);
     noStroke();
     rect(_deviceDisplayX,_deviceItemY[j],_deviceDisplayW,_deviceItemH);
     fill(0);
     textSize(42);
     text(deviceArray[j], _deviceDisplayX + 10, _deviceItemY[j] + 15, _deviceDisplayW, _deviceItemH);
    }  
   }
  }  else {
    if (deviceArray.length > 0) {    
     fill(BLUE);
     noStroke();
     rect(_deviceDisplayX, _deviceDisplayY, _deviceDisplayW, _deviceItemH * numDevices * 2);
    }
   } 
  }
 
 }

DeviceList deviceList;

 class ConnectBtn {
 // Changes color from gray to green when bluetooth is connected  
 void display(){
 if(connectSelected) {
   fill(151,186,66,255); // background color - GREEN
   noStroke();
   rect(_connectBtnX, _connectBtnY, _connectBtnW, _connectBtnH, 15);
   fill(0); // text color
   textSize(42);
   text("Disconnect", _connectBtnX + 20, _connectBtnY + 15, _connectBtnW, _connectBtnH);
  } else {
   fill(209); // background color - GRAY
   noStroke();
   rect(_connectBtnX, _connectBtnY, _connectBtnW, _connectBtnH, 15);
   fill(0); // text color
   textSize(42);
   text("Connect", _connectBtnX + 20, _connectBtnY + 15, _connectBtnW, _connectBtnH);
  }
 }
 
 void press() {  
  if(connectSelected == false){
  //  connectBluetooth();
    connectSelected = true;
    println("Connect selected.");
    connectThread = new ConnectThread(bluetoothAdapter.getRemoteDevice(deviceAddress[selectedDevice]));
    connectThread.run();
    } else {
      //disconnectBluetooth();
    connectSelected = false;
    println("Disconnect selected.");
    connectThread.cancel();
   }
 }
}

ConnectBtn connectBtn;

class QuitBtn {
  
 void display(){
   fill(209); // background color - GRAY
   noStroke();
   rect(_quitBtnX, _quitBtnY, _quitBtnW, _quitBtnH, 15);
   fill(0); // text color
   textSize(42);
   text("Quit", _quitBtnX + 25, _quitBtnY + 15, _quitBtnW, _quitBtnH);
 }
 
 void press(){
   exit();
 }
  
}
QuitBtn quitBtn;

// **** Android Code for Bluetooth Connection **** //
class ConnectedThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final InputStream mmInStream;
    private final OutputStream mmOutStream;

    public ConnectedThread(BluetoothSocket socket) {
        mmSocket = socket;
        InputStream tmpIn = null;
        OutputStream tmpOut = null;
        // Get input and output streams using temp objects because
        // member streams are final
        try {
            tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
        } catch (IOException e) { }

        mmInStream = tmpIn;
        mmOutStream = tmpOut;
    }

   public void run() {
   println("ConnectedThread: run() called.");
   // N.B. Set for line feed delimiter
   final byte delimiter = 10; //This is ASCII code for a lf
   stop_thread = false;
   buffer_index = 0;
   readBuffer = new byte[1024];   
    // Read from InputStream until an exception occurs
        while (true) {
          try {            
          int bytesAvailable = mmInStream.available();                        
          if (bytesAvailable > 0) {
            byte[] packetBytes = new byte[bytesAvailable];
            mmInStream.read(packetBytes);
            for (int i = 0; i < bytesAvailable; i++) {
              byte b = packetBytes[i];
              if (b == delimiter) {
                byte[] encodedBytes = new byte[buffer_index];
                System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
                final String data = new String(encodedBytes, "US-ASCII");
                println("data =", data);
                //plot(data);

                text(data, 1200, 100);
                buffer_index = 0;
              } else {
                readBuffer[buffer_index++] = b;
              }
            }
          }  
                
            }
            catch (IOException e) {
                break;
            }
        }
    }
    /* Call this from the main activity to send data to the remote device */
    public void write(byte[] bytes) {
        try {
            mmOutStream.write(bytes);
        } catch (IOException e) { }
    }

    /* Call this from the main activity to shutdown the connection */
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) { }
    }
}

ConnectedThread connectedThread;

class ConnectThread extends Thread {
 final BluetoothSocket mmSocket;
 final BluetoothDevice mmDevice;

    public ConnectThread(BluetoothDevice device) {
        // Use a temporary object that is later assigned to mmSocket because mmSocket is final.
        BluetoothSocket tmp = null;
        mmDevice = device;

        try {
            // Get a BluetoothSocket to connect with the given BluetoothDevice.
            tmp = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"));
        } catch (IOException e) {
            println("Socket's create() method failed");
        }
        mmSocket = tmp;
    }

void manageConnectedSocket(BluetoothSocket socket) {
    connectedThread = new ConnectedThread(socket);
    connectedThread.start();
}

    public void run() {
        // Cancel discovery because it otherwise slows down the connection.
        bluetoothAdapter.cancelDiscovery();

        try {
            // Connect to the remote device through the socket. This call blocks
            // until it succeeds or throws an exception.
            mmSocket.connect();
        } catch (IOException connectException) {
            // Unable to connect; close the socket and return.
            println("Could not connect to the client socket: ", connectException);
            try {
                mmSocket.close();
            } catch (IOException closeException) {
                println("Could not close the client socket: ", closeException);
            }
            return;
        }
     // Connection attempt succeeded; perform work associated with connection in separate thread.
        manageConnectedSocket(mmSocket);
    }
    // Closes the client socket and causes the thread to finish.
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) {
            println("Could not close the client socket");
        }
    }
}

ConnectThread connectThread;

void setup() {
  fullScreen();
  background(BLUE); 
  orientation(LANDSCAPE);  
  findPairedBluetoothDevices();
  deviceDisplay = new DeviceDisplay();
  deviceList = new DeviceList();
  deviceListDrop = false;
  connectBtn = new ConnectBtn();
  connectSelected = false;
  quitBtn = new QuitBtn();
  frameRate(60);
}

void draw() {
 background(BLUE);
 // maintains display of buttons 
 deviceDisplay.display();
 if(deviceListDrop == true) {
  deviceList.display();
 }
 connectBtn.display();
 quitBtn.display();
 /*
   fill(151,186,66,255); // background color - GREEN
   noStroke();
   rect(_dataDisplayX, _dataDisplayY, _dataDisplayW, _dataDisplayH, 15);
 */
}

// traps button touches
void mousePressed(){
 if((mouseX >= _deviceArrwX) && (mouseX <= _deviceArrwX+_deviceArrwSize) && (mouseY >= _deviceArrwY) && (mouseY <= _deviceArrwY+_deviceArrwSize)){
  deviceDisplay.press();
 }  
 if(deviceListDrop) {
  if((mouseX >= _deviceDisplayX) && (mouseX <= _deviceDisplayX + _deviceDisplayW) && (mouseY >= _deviceDisplayY + _deviceDisplayH) && (mouseY <= _deviceDisplayY + _deviceDisplayH + deviceArray.length*_deviceItemH)) {
    deviceList.press(mouseX, mouseY);
   }
 }
  
 if((mouseX >= _connectBtnX) && (mouseX <= _connectBtnX+_connectBtnW) && (mouseY >= _connectBtnY) && (mouseY <= _connectBtnY+_connectBtnH)){
  connectBtn.press();
 }

 if((mouseX >= _quitBtnX) && (mouseX <= _quitBtnX + _quitBtnW) && (mouseY >= _quitBtnY) && (mouseY <= _quitBtnY + _quitBtnH)){
  quitBtn.press();
 }

}

Thanks for it, and one question. Is there like a simple code that just works like sending and receiving data over bluetooth serial?

Just plain desktop serial is pretty simple in Processing, but when you add Android bluetooth it’s not simple anymore. BluetoothLE is really special. Don’t let the length of the code dampen your enthusiasm; it’s not as bad as it seems.

What’s on the other end, sending the data? Arduino is common.

Its basically to press one button on the phone and a led will turn on, press another button and the led will turn off, nothing more

Its basically to press one button on the phone and a led will turn on, press another button and the led will turn off, nothing more

Where’s the led?

Im doing it with an ESP32, thats why I want bluetooth serial

I’m used to data going from the board to the Android; apparently you want to go in reverse - from Android to the board.

I managed to create a very simple program, and I have a question, and is that why when I press the square it keeps sending the string even if I release the square area on the screen?

import ketai.net.bluetooth.*;
import android.os.Bundle;
String device_name = "PROMEESP32";
String device_mac = "78:21:84:97:F9:5E";
KetaiBluetooth bt;
void setup(){
  fullScreen();
  orientation(LANDSCAPE);
  bt = new KetaiBluetooth(this);
  bt.getPairedDeviceNames();
  bt.start();
  bt.connectToDeviceByName(device_name);
}
void draw(){
  fill(17,216,178);
  rect(100,100,100,100);
  if(mouseX >= 100 && mouseX <= 200){
    if(mouseY >= 100 && mouseY <= 200){
      String str = "Cuadrado presionado \n";
      byte[] data = str.getBytes();
      bt.writeToDeviceName(device_name, data);
      text("                      ",100,400);
    }
  }
  else{
    text("Pantalla sin presionar",100,400);
  }
}

Apparently if you place a “delay(100);” below it, the problem is fixed, but I don’t know why

Your code works well on my system; I substituted my bluetooth device name and MAC and it connected to it, no problem. Now if you can just figure out how to send a ‘1’ or ‘0’ you’ll have it made. I got a prototype working here with a modification of the code that I posted, but I used two buttons: ‘on’ and ‘off’. You may have to add another square to your demo and then send a ‘1’ or a ‘0’ depending on which is pressed. I have Arduino code that will read the value on the other end, but I don’t know if it will run on your ESP32. Nice work so far; if you can finish it you will have done it with a lot less code than I used.

I have it working on my system using your ketai code, but I’m not going to post it until you’ve had a chance to do it for yourself. I did use two buttons and trapped touches under mousePressed() rather than in draw() as you initially posted. After trapping the button touch, data was sent with a variation of the method in your demo:

 int ledValue = 0; // or ledValue = 1; depending on which btn is hit.
 String str = String.format("%d", ledValue);
 byte[] data = str.getBytes();
 bt.writeToDeviceName(device_name, data);

It works well here; thanks for posting.

Hi

Some informations here

1 Like

Hi

receiving via ketai library here is some notes