Universal Bluetooth/Hotspot/WiFi API & Unlock Demo

by Fran T

Version 20 (October 10, 2023)

Download (2,942 downloads)

Demonstrates the use of the Bluetooth, Wi-Fi, and Hotspot Set State blocks, as well as non-rooted UI workarounds for Android 8 and higher, where the blocks may no longer work due to security changes. Feel free to take the pieces you need for your flows.

Note: The "access deprecated system features" permission and Automate Legacy Extension are not required for this flow to operate. If you don't enable that permission (or install the extension), the flows will use the Quick Setting UI workarounds instead.

Thanks to Kevin for identifying the necessary lock screen UI element!
https://groups.google.com/forum/m/#!msg/automate-user/ymNjrewtODg/akJgitYtCAAJ

The flow detects whether the UI workaround is needed by checking for an exception from the Bluetooth, Wi-Fi, or Hotspot block during setup. In order for the UI method to be able to turn the setting on and off in Android 8 and above without extra permission, its tile must be present in Quick Settings. To see if it is, expand the status bar by swiping down twice. If the tile isn't present, tap the EDIT or “pen” button, then drag the tile to add it. If the Quick Setting tile on your device is labeled something other than "Bluetooth", "Hotspot", or "Wi-Fi" and the flow can't find them, change the 'quickSettingTileText' variable near the top of the relevant flow to match it. Note that for Wi-Fi, you'll need to surround the text with asterisk wildcards so that the setting can be found when you're connected to a Wi-Fi network. See this flow which generates the necessary XPath for you:

https://llamalab.com/automate/community/flows/39656

Note that the flow needs to unlock the device as necessary to access Quick Settings. A separate demo flow for that is provided. That section and the Bluetooth/Hotspot/Wi-Fi setting sections are written as subroutines to make them easier to extract for your own flow.

Note: If you notice an exception in the log, that's normal and is the way the flow determines whether the non-root/non-Legacy Extension UI workaround is needed to enable the setting. The flow continues to run normally.

Updates:
o Added positive re-locking for Android 9+
o Adaptations for Android 11 and new Automate behavior
o Added separate flow to demonstrate unlocking the device
o Updated to use the new Automate v1.24 workaround for the Wi-Fi Set State block
o Added wildcards to quick setting tile text XPaths to make them more likely to work on different devices
o Improved support for Samsung devices
o Added support for Bluetooth setting

4.8 average rating from 8 reviews

5 stars
7
4 stars
0
3 stars
1
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.