Beispiel #1
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
          // Waking up mobile if it is sleeping
          WakeLocker.acquire(getApplicationContext());

          /**
           * Take appropriate action on this message depending upon your app requirement For now i
           * am just displaying it on the screen
           */

          // Showing received message
          lblMessage.append(newMessage + "\n");
          Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG)
              .show();

          // load url into web view

          /*
             webSettings = mainWebView.getSettings();

          //   mainWebView.setWebViewClient(new MyCustomWebViewClient());
             mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

             mainWebView.loadUrl("http://google.com");*/

          // Releasing wake lock
          WakeLocker.release();
        }
Beispiel #2
0
        @Override
        public void onReceive(Context context, Intent intent) {
          lblMessage = new TextView(getApplicationContext());
          String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
          // Waking up mobile if it is sleeping
          WakeLocker.acquire(getApplicationContext());

          // new message code here

          // Releasing wake lock
          WakeLocker.release();

          /**
           * Take appropriate action on this message depending upon your app requirement For now i
           * am just displaying it on the screen
           */

          // Showing received message
          lblMessage.append(newMessage + "\n");
          Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG)
              .show();

          // Releasing wake lock
          WakeLocker.release();
        }
        @Override
        public void onReceive(Context context, Intent intent) {
          String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);

          WakeLocker.acquire(getApplicationContext());

          lblMessage.append(newMessage + "\n");
          Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG)
              .show();

          WakeLocker.release();
        }
Beispiel #4
0
 @Override
 public void run() {
   try {
     Log.d("TIME_UPDATER", "time updater thread started");
     if (owner == null) {
       Log.d("TIME_UPDATER", "time updater thread stopped, owner == null");
     }
     autoUpdateTime();
     Log.d("TIME_UPDATER", "time updater thread finished");
   } finally {
     WakeLocker.release();
   }
 }
  @Override
  protected void onHandleIntent(Intent intent) {
    String name = null;

    try {
      name = intent.getAction();
      Log.d("httpmon", "received intent for: " + name);
      if (name == null) {
        Log.w("httpmon", "name was null, returning");
        return;
      }

      Monitor monitor = mPrefs.getMonitor(name);
      if (monitor == null) {
        Log.w("httpmon", "monitor was null for name: " + name + ", returning");
        return;
      }

      int currentState = monitor.getState();
      monitor.setState(Monitor.STATE_STARTED);
      mPrefs.setMonitor(monitor);
      sendBroadcast(new Intent("ManageMonitors.update"));

      if (!isNetworkConnected()) {
        Log.w("httpmon", "was not connected when checking monitor: " + name + ", returning");
        return;
      }

      monitor.setState(Monitor.STATE_RUNNING);
      mPrefs.setMonitor(monitor);
      sendBroadcast(new Intent("ManageMonitors.update"));

      Response response = getResponseFromHttpClient(monitor.getRequest());
      currentState = Monitor.STATE_VALID;

      if (response.getThrowable() != null) {
        //
        // don't bother checking conditions if we get an exception
        //
        Log.w(
            "httpmon",
            "exception occured for monitor: " + monitor.getName(),
            response.getThrowable());
        currentState = Monitor.STATE_INVALID;
      } else {
        //
        // check conditions
        //
        for (int i = 0; i < monitor.getConditions().size(); i++) {
          Condition c = monitor.getConditions().get(i);
          if (!c.isValid(response)) {
            currentState = Monitor.STATE_INVALID;
            Log.e(
                "httpmon",
                "monitor: "
                    + monitor.getName()
                    + " INVALID, condition: "
                    + c.toString()
                    + " was false");
          }
        }
      }

      if (currentState == Monitor.STATE_VALID) {
        Log.i("httpmon", "monitor: " + monitor.getName() + " valid");
      }

      monitor = mPrefs.getMonitor(monitor.getName());
      if (monitor != null && monitor.getState() != Monitor.STATE_STOPPED) {
        monitor.setState(currentState);
        monitor.setLastUpdatedTime();

        for (int i = 0; i < monitor.getActions().size(); i++) {
          Action action = monitor.getActions().get(i);
          if (monitor.getState() == Monitor.STATE_INVALID) {
            action.failure(this, monitor);
          } else if (monitor.getState() == Monitor.STATE_VALID) {
            action.success(this, monitor);
          }
        }
        mPrefs.setMonitor(monitor);
        sendBroadcast(new Intent("ManageMonitors.update"));
      }
    } finally {
      if (name != null) {
        WakeLocker.release(name);
      }
    }
  }