1、客户端锁屏状态,无法发送心跳包
解决方案:使用电源锁
客户端:NotificationService
增加属性:
/** * 设备电源锁。 */ private PowerManager.WakeLock mWakeLock;
/** * 申请设备电源锁 */ private final void acquireWakeLock() { if (mWakeLock == null) { PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getPackageName()); } if (mWakeLock != null) { mWakeLock.acquire(); Log.d(LOGTAG, "mWakeLock.acquire()"); } } /** * 释放设备电源锁 */ private final void releaseWakeLock() { Log.d(LOGTAG, "releaseWakeLock"); if (mWakeLock != null) { mWakeLock.release(); mWakeLock = null; } }
@Override public void onStart(Intent intent, int startId) { Log.d(LOGTAG, "onStart()..."); acquireWakeLock(); }
private void stop() { Log.d(LOGTAG, "stop()..."); unregisterNotificationReceiver(); unregisterConnectivityReceiver(); xmppManager.disconnect(); executorService.shutdown(); releaseWakeLock(); }