关于androidpn消息推送客户端锁屏状态,无法发送心跳包解决方案

来源:互联网 发布:mmd恋爱循环数据 编辑:程序博客网 时间:2024/04/30 17:45


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;}}

@Overridepublic 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();}



0 0