Exemplo n.º 1
0
  @Override
  public void onCreate() {
    super.onCreate();
    singleton = this;

    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    try {
      mStartForeground =
          getClass().getMethod("startForeground", new Class[] {int.class, Notification.class});
    } catch (NoSuchMethodException e) {
      mStartForeground = null;
    }

    state = STATE_STOPPED;
    filteringEnabled = false;

    app = (BarnacleApp) getApplication();
    app.serviceStarted(this);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BarnacleService");
    wakeLock.acquire();

    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityReceiver, filter);
  }