I wanted to use Taifun's extension and found what I think can be a bug, at least with the versions I used. I made a test case as simple as I could.
It is enough to run the test several times, pressing back button, and see how the value decreases about 14% every time until it gets to 0.
Thanks Taifun for your extension and for any advice.
Regards.
FWIW, it also happens with Alarm volume, but not with Music volume. Music volume is o.k.
The 14% decrease happens within the BackPressed block. If the app is closed without pressing the Back button, subsequent readings remain constant.
Update:
I tried with Android 5.0.2 (Companion 2.46) and Android 8.1.0 (Companion 2.60).
I used these blocks, easier to test with just the read and write buttons:
Seemingly the decrement does not happen when the value is an exact ten (60, 80...) I saw this in Android 5, I could not set the volume to an exact ten in Android 8 (I will continue and try to set it in a program block).
Update2:
I continued with these blocks:
With Android 5 I can set volume to 80, 60... and it remains unchanged. Not exact ten values get changed with write then read.
With Android 8 I cannot set volume to 80, 90, 60... it gets changed, (decreased).
Further investigation is beyond my knowledge.
Regards.
Get ring volume in percent. Thank you Merciful for being the sponsor of this property!
Note: to set Ringtone for >= Android N during DO NOT DISTURB mode: the permission ACCESS_NOTIFICATION_POLICY is required. Therefore the new method HaveNotificationPolicyAccess and the event NoNotificationPolicyAccess have been added into the paid version.
For the free version this property only works for devices below Android 9.
My English is not good. But I understood that the reading volume method only works on android 9. There is no point in using something that only works on one android version. Maybe the paid version will be more appropriate.
Thank you for your help. I read this note, but I understand that this restriction is only in DO NOT DISTURB mode, which is not my case. It might be related though.
Regards.
It looks like I cannot further edit my initial post. So I share my last findings here.
My phone (the Android 8 one) accepts the following levels (as read via your extension): 0,14,28,42,57,71,85,100.
I add 1 to the level read, before I write it back. This way I can restore the level the volume had before my app eventually changed it.
I guess other devices have different volume steps.
Thanks again & regards.
each device is different, but the extension calculates the volume in percent like this
to get the volume volume = deviceVolume * 100 / maxVolume
to set the volume deviceVolume = maxVolume * enteredVolume / 100
as mentioned in the documentation , to set the ring volume is only possible for devices < API Level 28 (free version)
Note: to set Ringtone for >= Android N during DO NOT DISTURB mode: the permission ACCESS_NOTIFICATION_POLICY is required. Therefore the new method HaveNotificationPolicyAccess and the event NoNotificationPolicyAccess have been added into the paid version.
For the free version this property only works for devices below Android 9.