Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash fix for Android OS Version > 30 #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dinesh-thiyagarajan
Copy link

@dinesh-thiyagarajan dinesh-thiyagarajan commented Oct 27, 2022

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

  • I have made my changes on a new branch.
  • My code follows the code style of this project.
  • I made a round of sanity check and the app is working fine on foreground and background

@TheLastProject

@TheLastProject
Copy link
Owner

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
Copy link
Author

dinesh-thiyagarajan commented Oct 28, 2022

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
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants