kraigs-android / kraigsandroid

Kraig's android applications
26 stars 26 forks source link

Can't use system alarm sound #144

Closed Zukero closed 3 years ago

Zukero commented 3 years ago

Hi, and thank you for the klock. Been using it since Android 2.1!

I just switched to a Pixel 4a 5G, running Android 11.

In the system settings, I can set different sounds for notifications and alarms.

Alarm Klock uses the notification setting as the system default alarm, instead of the alarm. I guess calling DEFAULT_ALARM_ALERT_URI instead of DEFAULT_NOTIFICATION_URI should do the trick. Or maybe offer both.

On a related note, there are plenty of system internal ringtones I can't find in the MediaPicker's internal tab, but that may be device/permissions related... If it's relevant, I can open a second issue.

kraigs-android commented 3 years ago

Indeed it should be relatively straight forward to add the other DEFAULT_*_URI targets to the app. I don't believe the ALARM version existed in the public API when I first wrote this app, so that's the only reason it's not there.

As for the other 'system' ringtones you mention, I'm guessing you actually mean the things provided by the Google Sounds app? (https://play.google.com/store/apps/details?id=com.google.android.soundpicker) 'Pixel Sounds', 'Retro Riffs', etc?

Technically those aren't 'internal' sounds. The 'internal' media the klock app recognizes are those installed as part of the base android ROM installed on your phone (via Audio.Media.INTERNAL_CONTENT_URI). The sounds in the Google Sounds app are part of that app and exposed through a service provider in the app. In theory, it should be possible to extend the Klock app to use the same provider, but the API is not documented (at least, I've never been able to find one). It's also probably possible to reverse-engineer it given what is public information in the android source repositories, but Google will almost certainly change this API at some point. I don't think I'm interested in supporting this one-off API.

However, if you use that app to set the default ringtone, notification, alarm, etc settings for the phone, Alarm Klock should still be able to play those sounds through the DEFAULT_*_URI targets mentioned above. So hopefully adding those additional URIs should be good enough for what you want.

I'm a bit swamped at the moment, but I may have some time to try to build a new release over the holidays. I'll leave this open as a reminder...

Zukero commented 3 years ago

Thanks for the reply. Sounds nice.

Your guess was on spot. I agree that relying on 3rd-party, undocumented API is not worth the trouble, and might actually degrade the appeal of alarm klock. Setting them up as system default and calling them from your app sounds like the best trade off.

I'll try to find the will to reinstall Android Studio and send a PR for this if I can.

kraigs-android commented 3 years ago

Thanks for the fix. I read-up on the Google Sounds app a bit and found that it implements the RingtoneManager API defined in the android docs. The default implementation of this on most android phones seems pretty terrible, so it's not a reasonable replacement for this apps media picker, but it's pretty easy to add a button to trigger the RingtoneManager interface.

I tried a hack that adds an 'other' button to the media picker in this commit: https://github.com/kraigs-android/kraigsandroid/commit/5c5fafa4cf96d6aef91c8c660823432dad09791c It's not very pretty, but it seems to work.

I also uploaded a build that contains your fix and this one here: https://github.com/kraigs-android/kraigsandroid-downloads/raw/master/Alarm%20Klock-2.10.apk

I'm going to test it for a few days before I upload it to the play store.

Zukero commented 3 years ago

👍