FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
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
Connectez-vous…
Jonathan
#1
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;
}
Signaler
0
0
Jonathan
#2
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;
}
Signaler
0
0
Papaxas
#3
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?
Signaler
0
0
→ Revenir à WINDEV Mobile 27
WINDEV 27
WEBDEV 27
WINDEV Mobile 27
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte