|
FOROS PROFESIONALES WINDEV, WEBDEV y WINDEV Mobile |
| | | | | |
bluetooth permissions bluetooth_scan bluetooth_connect android 12 |
Iniciado por Jonathan, 29,nov. 2022 00:20 - 3 respuestas |
| |
| | | |
|
| |
Publicado el 29,noviembre 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; } |
| |
| |
| | | |
|
| | |
| |
Publicado el 29,noviembre 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; } |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 8 mensajes |
|
Publicado el 13,enero 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? |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 8 mensajes |
|
Publicado el 05,marzo 2023 - 14:58 |
Auto translation to French Après avoir lutté, débogué et lu, j'ai trouvé une solution qui a fonctionné pour moi. Pour toutes les versions Android, 10, 11, 12, 13 Android 11 n'a besoin de rien de différent concernant la dent bleue. Android 12 et versions ultérieures doivent analyser et se connecter au moment de l'exécution. Mais le système prend un certain temps jusqu'à ce que la boîte de dialogue s'affiche. Et dans Android 12, l'appareil doit être couplé une fois l'autorisation accordée. J'ai donc ajouté une boîte de dialogue si la connexion ne parvient pas à inviter l'utilisateur à réparer l'appareil. J'ai créé cette routine GrantPermissions en utilisant plusieurs if pour chaque version d'API différente. Concernant le stockage public, j'ai arrêté de l'utiliser et stocké les fichiers dans le stockage interne. Je le partage ici pour aider ceux qui pourraient en avoir besoin.
English After struggling and debugging and reading I 've come up to a solution that worked for me. For all android versions, 10, 11, 12, 13 Android 11 needs nothing different concerning blue tooth. Android 12 and above need scan and connect in runtime. But the system takes some time until the dialog is presented. And in Android 12 the device needs to be paired after the permission is granted. So I added a dialog if connection fails to prompt the user repair the device. I created this routine GrantPermissions using multiple if for every different API version. Concerning the public storage I quit from using it and store the files in internal storage. I share it here to help anyone else who might need it.
Procedure GrantPermissions()
ProgressBar1=0
IF ApiVersion<=30 THEN RETURN True IF ApiVersion=30 THEN ELSE IF ApiVersion>=31 THEN WHILE Grantedconnect=False OR Grantedscan = False IF Grantedscan=False THEN PermissionRequest(Permission_BT_Scan,ProcRequestScan) END IF Grantedconnect=False THEN PermissionRequest(Permission_BT_Connect,ProcRequestConnect) END ProgressBar1=ProgressBar1+4 Multitask(50) END ChangePlane(MainPlane) RETURN Grantedconnect AND Grantedscan END
INTERNAL Procedure ProcRequestScan(Perm1 is Permission) IF Perm1.Granted THEN Grantedscan=True END END
INTERNAL Procedure ProcRequestConnect(Perm is Permission) IF Perm.Granted THEN HourGlass(True) sListDevices="" sListDevices = BTListDevice(2000) HourGlass(False) Grantedconnect=True END END
|
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|