PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 27 → bluetooth permissions bluetooth_scan bluetooth_connect android 12
bluetooth permissions bluetooth_scan bluetooth_connect android 12
Débuté par Jonathan, 29 nov. 2022 00:20 - 2 réponses
Posté le 29 novembre 2022 - 00:20
New permissions for android 12 and on
Java code for asking those permissions

import android.content.pm.PackageManager;
import androidx.annotation.NonNull;;
import androidx.core.app.ActivityCompat;;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Build;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;

public static int BTPermissions()
{

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
int REQUEST_CODE = 1;
Activity currentActivity = getCurrentActivity();

if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(currentActivity,new String[] {android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_ADVERTISE}, REQUEST_CODE);
return 0;
}
}
return 1;

}
Posté le 29 novembre 2022 - 19:08
Quicker way to get paired devices, especially android 12 with new permissions bluetoo

import android.content.pm.PackageManager;
import androidx.annotation.NonNull;;
import androidx.core.app.ActivityCompat;;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Build;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;

public static String BTgetPairedDevices()
{
String BTList = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
int REQUEST_CODE = 1;
Activity currentActivity = getCurrentActivity();

if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(currentActivity,new String[] {android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_ADVERTISE}, REQUEST_CODE);
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
return "";
}
}

BluetoothAdapter mBluetoothAdapter;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set pairedDevices = mBluetoothAdapter.getBondedDevices();
// mBluetoothAdapter.startDiscovery();

if (pairedDevices.size() > 0) {
// There are paired devices. Get the name and address of each paired device.
for (BluetoothDevice device : pairedDevices) {
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress(); // MAC address
if (BTList != "") {
BTList = BTList + "\r\n";
}
BTList = BTList + "1\t" + deviceHardwareAddress + "\t" + deviceName;
}
}

return BTList;

}
Membre enregistré
3 messages
Posté le 13 janvier 2023 - 19:47
Hello. Great tool missing from Windev. I don't know Java and I cannot add it in. I made global procedure. Turned into Java. Now I need to find the external dependencies and I have a really hard time searching and searching which jar file I need to add. Can you tell us a bit more of instructions? Where do we locate all the jar or aar files to make this code work?