Request ignore battery opt instead of openning settings
This commit is contained in:
parent
b43eb46f0d
commit
8c0d23344c
|
@ -5,6 +5,7 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.unifiedpush.distributor.nextpush.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
|
@ -107,17 +110,33 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
private fun showOptimisationWarning() {
|
||||
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
|
||||
findViewById<MaterialCardView>(R.id.card_battery_optimization).isGone = false
|
||||
findViewById<Button>(R.id.button_disable_optimisation).setOnClickListener {
|
||||
startActivity(Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS))
|
||||
findViewById<MaterialCardView>(R.id.card_battery_optimization)?.isGone = false
|
||||
findViewById<Button>(R.id.button_disable_optimisation)?.setOnClickListener {
|
||||
try {
|
||||
startActivity(
|
||||
Intent(
|
||||
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
Uri.parse("package:$packageName")
|
||||
)
|
||||
)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
try {
|
||||
startActivity(Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS))
|
||||
} catch (e2: ActivityNotFoundException) {
|
||||
startActivity(Intent(Settings.ACTION_SETTINGS))
|
||||
}
|
||||
}
|
||||
findViewById<MaterialCardView>(R.id.card_battery_optimization)?.isGone = true
|
||||
}
|
||||
} else {
|
||||
findViewById<MaterialCardView>(R.id.card_battery_optimization)?.isGone = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun restart() {
|
||||
Log.d(TAG, "Restarting the Listener")
|
||||
FailureHandler.clearFails()
|
||||
|
|
Loading…
Reference in New Issue