Updates for Android 12 Bluetooth Permissions

February 14, 2023 by Long Pan | DEV COMMUNITY UPDATES


As you may know, Google has been pushing developers to update their apps for Android 12 and newer OS. Among the many changes was a set of Bluetooth permission changes. The single Bluetooth permission required in Android 11 and older version has been changed to three different Bluetooth permissions that covers device discovery, advertisement, and connection separately Opens New Window. In addition, if an app update targets API 31 or above, the Bluetooth permission will not automatically renew. The updated app needs the users' explicit approval.

As we are preparing to update our Socket Mobile Companion app and CaptureSDK to support Android 12, we realized that the transition could potentially cause device connection issues that interrupt end user's workflow. To avoid these interruptions as much as possible, we are making additional changes to ensure the end users will have a smooth experience for the transition:

  • First, we want to make sure that when a user updates their Companion app, they will be prompted to provide permission for Bluetooth. The Companion app will also send out an urgent notification at launch time when it starts the Companion service. However, if users have a scanner already connected and working, they may not revisit the Companion app and the scanner connection can still be interrupted. This is especially true if they set the Companion app for automatic updates.
  • To avoid this issue, we highly recommend you also take proactive actions in updating your app to take advantage of the SDK changes we are making:

The Capture Service provided through the Companion app will try to detect when the required Bluetooth permission is missing and return an error (with a new error code ESKT_BLUETOOTHPERMISSIONMISSING). Your app should handle this error properly and prompt the user to provide permission in the Companion app. Your app can also check the Bluetooth permission status before starting Capture. Here's a code snippet:

if (captureError.getCode() == CaptureError.ESKT_BLUETOOTHPERMISSIONMISSING) {
	Intent intent = new Intent();
	intent.setClassName("com.socketmobile.companion", "com.socketmobile.companion.GetPermission");
//Start activity result 
ActivityResultLauncher < Intent > permissionActivityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback < ActivityResult > () {
	public void onActivityResult(ActivityResult result) {
		if (result.getResultCode() == Activity.RESULT_OK) {
			Intent data = result.getData();
			int permissionResult = data.getIntExtra(Permissions.EXTRA_GRANT_RESULT, PackageManager.PERMISSION_DENIED);
			switch (permissionResult) {
				case PackageManager.PERMISSION_GRANTED:
					// Continue using the Capture SDK to scan barcodes 
				case PackageManager.PERMISSION_DENIED:
					// Notify user that permission is required to use bluetooth scanner 

The updated Companion and SDK are scheduled to be released around mid-March. We have a Beta version ready for test upon request. If you have any concerns or questions, please reach out via the normal developer support email or by using the feedback form Opens Worldwide Website (AU, EMEA, UK).