Merhaba arkadaşlar.
Android Studio ile Bluetooth uygulaması yapıyorum. Sistem hata vermiyor ancak çalışmıyorda

Çözümü bulana 200 lira vermek istiyorum. Biliyorum çok bir para değil ancak bütçem ne yazık ki bu kadar. Teşekkür ederim.
Arduino Tarafı
```
#include <SoftwareSerial.h>
int RX = 4;
int TX = 5;
SoftwareSerial bluetooth(RX,TX);
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
Serial.println("Already");
pinMode(13, OUTPUT);
}
void loop() {
if (bluetooth.available()) {
char c = bluetooth.read();
if(c == 'a'){
digitalWrite(13, HIGH);
Serial.println("Led High");
}
if(c == 'b'){
digitalWrite(13, LOW);
Serial.println("Led Low");
}
}
}
```
AndroidManifest
```
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT "/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTI SE" />
```
Activity_main.XML
```
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/highButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HIGH"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="679dp"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/lowButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="low"
android:layout_below="@+id/highButton"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="679dp"
tools:ignore="MissingConstraints" />
</RelativeLayout>
```
MainActivity.java
```
public class MainActivity extends AppCompatActivity {
public String TAG = "-----------";
private String macAddress = "";
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
Button high,low;
BluetoothAdapter bluetoothAdapter;
BluetoothDevice bluetoothDevice;
BluetoothSocket bluetoothSocket;
OutputStream outputStream;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
high = findViewById(R.id.highButton);
low = findViewById(R.id.lowButton);
if (ActivityCompat.checkSelfPermission(MainActivity.t his, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_DENIED) {
if (Build.VERSION.SDK_INT > 31) {
ActivityCompat.requestPermissions(MainActivity.thi s, new String[]{android.Manifest.permission.BLUETOOTH_CONNECT}, 100);
return;
}
}
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : pairedDevices) {
System.out.println("Name->" + device.getName() + " " + "MAC->" + device.getAddress());
if (device.getName().equals("HC-06")) {
macAddress = device.getAddress();
System.out.println("MAC - > " + macAddress);
}
}
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothDevice = bluetoothAdapter.getRemoteDevice(macAddress);
// Connecting to bluetooth device in a separate thread;
new Thread(new Runnable() {
@Override
public void run() {
if (ActivityCompat.checkSelfPermission(MainActivity.t his, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_DENIED) {
if (Build.VERSION.SDK_INT > 31) {
ActivityCompat.requestPermissions(MainActivity.thi s, new String[]{Manifest.permission.BLUETOOTH_CONNECT}, 100);
return;
}
}
try {
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord( uuid);
bluetoothAdapter.cancelDiscovery();
bluetoothSocket.connect();
outputStream = bluetoothSocket.getOutputStream();
Log.d("Message", "Connected to HC-06");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "Bluetooth successfully connected", Toast.LENGTH_LONG).show();
}
});
} catch (IOException e) {
Log.d("Message", "Turn on bluetooth and restart the app");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "Turn on bluetooth and restart the app", Toast.LENGTH_SHORT).show();
}
});
throw new RuntimeException(e);
}
}
}).start();
high.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
String a="a";
outputStream.write((a).getBytes());
Log.d("Command- >", a);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
low.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
String b="b";
outputStream.write((b).getBytes());
Log.d("Command- >", b);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (bluetoothSocket != null) {
try {
bluetoothSocket.close();
Log.d(TAG, "Connection closed");
} catch (IOException e) {
Log.d(TAG, "Error while closing the connection");
}
}
}
}
```