To support my bluetooth headset, my desire was to turn bluetooth on when I'm in the Contacts app OR in a call. I could do it only while in a call but then I can't make sure my headset is connected before the other party picks up.
None of the solutions already posted would work. Setting %BluetoothNeeded on when in Contacts or in call means that when a call starts, it sets %BlueToothNeeded on but then when Contacts becomes background to being in call, it sets %BlueToothNeeded off and bluetooth turns off. Using the inverse operation, turn bluetooth off when NOT in Contacts AND NOT in call but turn bluetooth on as an exit task almost works, but apparently Tasker notices the brief period when Contacts loses foreground status and the call hasn't started yet and turns bluetooth off.
So here's what worked for me, based on this blog:
- Create a Task called
Dummy with an Action of Tasks > Wait > 1ms
- Create a Profile called
stateInCall with a condition of State > Phone > Call > Type: Any. Link it to the Dummy task.
- Create a Profile called
stateInContacts with a condition of State > Application > Contacts. Link it to the Dummy task.
- Create a Profile called
Bluetooth Needed with a condition of State > Variable > Variable Value. Set Name to %PACTIVE, Op to Matches, and Value to *,stateInCall,*|*,stateInContacts,*. According to the Tasker docs, %PACTIVE contains a comma-separated list of active Profiles where the list also begins and ends with a comma to make matching easier. Link this Profile to a Task called Bluetooth On that turns bluetooth on using the Net > Bluetooth > Set: On Action.
- Create a Task called
Conditional Bluetooth Off with the following Actions:
- Task > Wait > 10 seconds
- Task > If >
%PACTIVE doesn't match *,stateInCall,*|*,stateInContacts,*
- Net > Bluetooth > Set: Off
- Task > End If
- Long press on the
Bluetooth Needed Profile then choose Properties. Uncheck Restore Settings.
- Quick press the
Bluetooth Needed Profile till the Bluetooth On Task appears below it, in the right column. Long press Bluetooth On and choose Add Exit Task, then choose Conditional Bluetooth Off.
Conditional Bluetooth Off will wait 10 seconds before double checking that neither stateInCall nor stateInContacts are true, at which point it will turn bluetooth off. Otherwise, it leaves bluetooth on and when both stateInCall and stateInContacts exit later, it will do its 10 second wait and check again.