TheLastProject / RaiseToAnswer

Simply hold your phone to your ear to answer an incoming call
https://play.google.com/store/apps/details?id=me.hackerchick.raisetoanswer
MIT License
75 stars 13 forks source link

Crash fix for Android OS Version > 30 #93

Open dinesh-thiyagarajan opened 1 year ago

dinesh-thiyagarajan commented 1 year ago

This PR fixes the issue #89 ie) android.app.ForegroundServiceStartNotAllowedException that happens when the app is in the background and the foreground service is initiated. due to the restrictions placed on Foreground services.

So in this PR by using checkPowerSettings method we initiate a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS which asks user to let the app always run in background.

Foreground service can be initiated from the background, If the user has grants the permission. below is the screenshot of ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS popup.

Screenshot_20221027_094109

Checklist

@TheLastProject

TheLastProject commented 1 year ago

Quite interesting! The only worry I have is that the crash will still happen if the user denies the permission. Could it be possible to maybe show a notification explaining the user they need to disable battery optimization (preferably clicking on the notification puts you in the battery settings) to help users who clicked the wrong thing?

dinesh-thiyagarajan commented 1 year ago

Valid point we can do that, what I'm worried about is google taking the app down from the play store citing that this app doesn't meet the usecase where we could use ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. that will make updating the app difficult for users.

I have added a question regarding this in StackOverflow ie) Not getting sensor events inside a work manager if the app is in the background. if we get a proper solution we can try to adapt that. (which is without any adverse effects from google)

TheLastProject commented 1 year ago

Yeah, I'm worried too. But if we do nothing Google is going to kick the app out of Google Play November 1st 2023 anyway. So trading a guaranteed getting kicked out for a possible getting kicked out still feels like an improvement to me :)

If a better way shows up, sure, that'd be more awesome, but this is already an improvement :)

TheLastProject commented 1 year ago

Let me just mark this hacktoberfest-accepted already because even though there's the small notification thing this is already super helpful :)