Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waseemsabir/batterypermissionhelper
This Library helps whitelist your Android App in Battery Settings, to prevent the app from getting killed due to Battery Optimisations.
https://github.com/waseemsabir/batterypermissionhelper
android android-library battery battery-optimization batterypermissionhelper java kotlin permission-android
Last synced: 11 days ago
JSON representation
This Library helps whitelist your Android App in Battery Settings, to prevent the app from getting killed due to Battery Optimisations.
- Host: GitHub
- URL: https://github.com/waseemsabir/batterypermissionhelper
- Owner: WaseemSabir
- License: mit
- Created: 2023-01-11T12:03:06.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-03T17:07:36.000Z (about 1 year ago)
- Last Synced: 2024-10-17T19:49:11.689Z (21 days ago)
- Topics: android, android-library, battery, battery-optimization, batterypermissionhelper, java, kotlin, permission-android
- Language: Kotlin
- Homepage:
- Size: 144 KB
- Stars: 25
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BatteryPermissionHelper
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
[![Android Build](https://github.com/WaseemSabir/BatteryPermissionHelper/actions/workflows/build.yml/badge.svg)](https://github.com/WaseemSabir/BatteryPermissionHelper/actions/workflows/build.yml)
[![Unit Tests](https://github.com/WaseemSabir/BatteryPermissionHelper/actions/workflows/tests.yml/badge.svg)](https://github.com/WaseemSabir/BatteryPermissionHelper/actions/workflows/tests.yml)
[![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16)An Android Library to detect battery optimizations settings and navigate the user to the relevant screens so that they can whitelist the app. This will prevent the app from getting killed in the background due to Battery Optimization Managers. The library supports multiple OEMs.
## Installation
### Gradle
Add this to your module's build.gradle file:
```gradle
dependencies {
// ... other dependencies
implementation 'com.waseemsabir:betterypermissionhelper:1.0.3'
}
```### Maven
```mavencom.waseemsabir
betterypermissionhelper
1.0.3```
Other instructions for installation can be viewed [here](https://central.sonatype.com/artifact/com.waseemsabir/betterypermissionhelper/1.0.0).
## Usuage
```kotlin
private val batteryPermissionHelper = BatteryPermissionHelper.getInstance()// check whether or not Battery Permission is Available for Device
val isBatteryPermissionAvailable = batteryPermissionHelper.isBatterySaverPermissionAvailable(context = context, onlyIfSupported = true)// Show a dialog based on availability (Implementation left to Dev) and OnClick open permission manager
dialog.setOnClickListener {
batteryPermissionHelper.getPermission(this, open = true, newTask = true)
}
```To keep the library small and extendable, UI elements (dialog/popups) implementation is left up to the library user. The library will not show any screens.
Currently, the library supports following devices.
1. Xiaomi
2. Redmi
3. Poco
4. Letv [ Untested ]
5. HTC [ Untested ]
6. Huawei
7. Oppo
8. Samsung
9. ZTE [ Untested ]
10. Meizu [ Untested ]I am open to any PR's and contributions for any devices. I'll also try to add more devices, whenever possible.
## Relevant Work
* [AutoStarter](https://github.com/judemanutd/AutoStarter)
* [dont-kill-my-app](https://github.com/urbandroid-team/dont-kill-my-app)