Reputation: 1291
I developed an Android app called Multi Countdown Timer In which we can start multiple timers at once. The App runs on the background using Foreground Service in order to run continuously and override's The Android Doze Mode.
I have tested my App on Samsung s6, A7, Nokia 3.1, LG Nexus 5x and some emulators. The Apps runs perfectly and Wake Up's when the timer finished. But on the other hand, whenever I run my App on Huawei Devices (EMUI 8 Android Oreo 8.0.0) the result is not satisfactory at all. The problem I'm facing is that the App didn't wake up the screen when the Timer is Finished and when the timer is finished when I open my device it rings then but didn't auto Wake Up the screen as it is working on the other devices.
I have replicated this App Multi Timer StopWatch and this App is working fine even on Huawei Devices.
This is my Activity in Manifest.xml.
android:name=".view.alarm.AlarmActivity"
android:process="alarm.process"
android:screenOrientation="portrait"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:theme="@style/splashScreenTheme" />
This is how I called my Alarm Activity.
val alarmIntent = Intent(this@CountDownTimerForegroundService, AlarmActivity::class.java)
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
}
alarmIntent.putExtra(ALARM_PASSING_ID, timerObj.id)
startActivity(alarmIntent)
And this is my Alarm Activity onCreate
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
or WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
or WindowManager.LayoutParams.FLAG_FULLSCREEN
or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)
setContentView(R.layout.activity_alarm)
Any Help will be highly appreciated. Thanks in Advance.
Update:
1) On Huawei device, I have tested after Whitelisting my app in PowerManager and also enabled Battery Optimization But it also didn't help out.
2) I have tested with some Wake Locks in my Foreground Service but still getting the same behavior.
3) Used Android AlarmManager with setExactAndAllowWhileIdle still didn't wake up the device.
4) Used Don'tKillMyApp Solution to use LocationManagerService Tag in Wake Lock also didn't help out.
Upvotes: 3
Views: 1767
Reputation: 316
Because they have their own battery management algorithm. Since Huawei's EMUI has very strict battery management policies. So whenever you running foreground service it will destroy it.
Upvotes: 0
Reputation: 11
Huawei equipment does not support foreground service and wakelocks(keep the background running) To keep the mobile phone running all the time in the background,the method is very simple.The method is: Click to enter the software which need to be run → enter the designated location → click home directly to exit → so that the software still running does not affect your operation of another software. The higher the configuration of mobile phone, the more software can run in the background.
Upvotes: 0
Reputation: 506
Huawei's EMUI has quite strict battery management policies. Apart from the permissions in Battery Management, there is a separate white-list managed by EMUI on the background.
Please refer to my answer on there; https://stackoverflow.com/a/61364065/5245066
Upvotes: 0