Pages

Labels

Sample (14) Intent (5) Media (5) Location (4) Funny (3) HTTP (3) Sleep as Android (3) WiFi (3) Alarm (2) Recording (2) Regexp (2) Array (1) Basic (1) Battery (1) Browser (1) Calculator (1) Contacts (1) Content Provider (1) Cron (1) Dialog (1) Dictionary (1) Export (1) Function (1) GUI (1) Game (1) Loop (1) Random (1) SD Card (1) Social (1) Temperature (1) Text to Speech (1) Weather (1)

Search Scripts

2012-02-18

Low Battery Notification

// Issue a notification when battery level is under 20%

triggered = false;
while(true) {
  // wait for the battery level changed intent
  // the second parameter makes the function ignores the first event which arrives immediately
  result = waitForIntent("android.intent.action.BATTERY_CHANGED", true);

  // this checks the level parameter form the battery intent, but there are more e.g.: temperature
  if (result["level"] < 20) {
    // Notify the user that battery is low - status bar
    if (triggered == false) {
        notify("Battery low", true);
        triggered = true;
    }
  }

  // reset the flag if battery gets charged again
  if (triggered) {
    if (result["level"] > 19) {
        triggered = false;
    }
  }

  // wait for a while if intents are coming too fast
  sleep(30000);

}


2 comments:

  1. An automotive battery is a type of rechargeable battery that supplies electric energy to an automobile. get redirected here

    ReplyDelete
  2. Very useful information, I have tryed to run this script and it really works! Thank you. See also information on this site

    ReplyDelete