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