VMWakeReceiver.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.vmloft.develop.daemon.receiver;
  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.util.Log;
  6. import com.vmloft.develop.daemon.VMDaemonManager;
  7. /**
  8. * 接收唤醒应用核心服务的广播接收器,接收守护进程发送过来的广播
  9. *
  10. * Created by lzan13 on 2017/3/7.
  11. */
  12. public class VMWakeReceiver extends BroadcastReceiver {
  13. private final static String TAG = VMWakeReceiver.class.getSimpleName();
  14. // 定义守护进程发送唤醒广播的 Action
  15. public final static String DAEMON_WAKE_ACTION = "com.vmloft.develop.daemon.wake";
  16. @Override public void onReceive(Context context, Intent intent) {
  17. String action = intent.getAction();
  18. if (action.equals(DAEMON_WAKE_ACTION)) {
  19. Log.i(TAG, "onReceive: 起床了!");
  20. // 接收到守护进程发送的广播,开始启动核心进程
  21. VMDaemonManager.getInstance().startCoreProcess();
  22. } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
  23. Log.i(TAG, "onReceive: 锁屏了!");
  24. // 检测到锁屏,启动一像素的流氓 Activity
  25. VMDaemonManager.getInstance().startDaemonActivity();
  26. } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
  27. Log.i(TAG, "onReceive: 解锁了!");
  28. // 解锁后,结束一像素的流氓 Activity
  29. VMDaemonManager.getInstance().finishDaemonActivity();
  30. }
  31. }
  32. }