Android broadcastreceiver not triggering when app is not running

后端 未结 2 1593
悲&欢浪女
悲&欢浪女 2021-01-20 02:59

Following this guide https://developer.android.com/training/monitoring-device-state/battery-monitoring.html

I made a receiver that should log battery info to a file

2条回答
  •  臣服心动
    2021-01-20 03:34

    Did you try using wake-locks? Generally app will wake up on the receive of broascast butif it doesnot (happens in few devices), then try using wake-locks which will forcefully wake up the device.

    How to use wake-locks :

    //Register for wake-locks

    if (mWakeLock == null) {
            PowerManager pm = (PowerManager)yourcontext.getSystemService(Context.POWER_SERVICE);
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, yourcontext);
            mWakeLock.setReferenceCounted(false);
    

    }

    //Apply wake-lock using acquire

    mWakeLock.acquire();
    

提交回复
热议问题