天道酬勤,学无止境

android-doze

Android Nougat PhoneStateListener is not triggered

Question In Android (target 25) I have a background service and in onCreate function I have initialized a phone state listener. It works fine on Android versions that are before Nougat but in Nougat it doesn't work, even though the permissions are granted. public class Service extends IntentService { class PhoneListener extends PhoneStateListener { String TAG = getClass().getName(); @Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.d(TAG,"IDLE" ); break; case

2021-06-28 11:18:28    分类:技术分享    android   telephonymanager   android-7.0-nougat   android-7.1-nougat   android-doze

how to turn off doze mode for specific apps in marshmallow devices programmatically

Question Marshmallow APIs are very different from previous android OS. When screen is off, devices are in doze mode and unable to sync network. So for doing background operations with network we have to prevent from doze mode. Answer1 Add below permission to manifest.xml <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/> Call below method public void turnOffDozeMode(Context context){ //you can use with or without passing context if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(); String packageName = context.getPackageName()

2021-06-24 09:58:17    分类:技术分享    android   android-6.0-marshmallow   android-doze   android-appstandby

How to shift device in Doze Mode (Android Preview M / Marshmallow)?

Question I followed steps described here: https://developer.android.com/preview/testing/guide.html#doze-standby Circumstances: Android Debug Bridge version 1.0.32 Nexus 9 with Preview M Shell: $ adb shell dumpsys battery unplug => worked, device unplugged $ adb shell dumpsys deviceidle step => Output: Stepped to: ACTIVE $ adb shell dumpsys deviceidle -h => does not work => Output: Device idle controller (deviceidle) dump options: [-h] [CMD] -h: print this help text. Commands: step disable enable whitelist I tried it with: adb shell dumpsys deviceidle enable But it didn't work. So my question

2021-06-22 08:11:25    分类:技术分享    android   android-6.0-marshmallow   android-doze

How do I properly fire ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent?

Question As stated in the documentation: "An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog." Can someone tell me the proper way to fire this intent? Answer1 Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent

2021-05-08 16:52:59    分类:技术分享    android   android-intent   optimization   android-6.0-marshmallow   android-doze

How does doze mode affect background/foreground services, with/without partial/full wakelocks?

Question This is a simple question, seeing that there is a huge post about this on G+ (here), and lack of information on official docs (here ): What happens to the app's services when the device goes to "doze" mode? What does it do to background/foreground services (bound/unbound, started/not-started), with/without partial/full wakelocks? What would you do, for example, in order to create a service that plays an audio stream while the device's screen is turned off? What if the audio stream is not from a local file, but from the network? Seeing that there was a claim by Google developer: Apps

2021-04-15 09:47:40    分类:技术分享    android   android-service   android-doze   android-doze-and-standby