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

}


6 comments:

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

    ReplyDelete

  2. Great article! We are linking to this great article on our site. Keep up the good writing.

    3 شركة مكافحة حشرات بالمدينة المنورة
    http://prokr.com/company-spraying-pesticides-anti-insects-in-al-madina/
    شركات مكافحة الحشرات
    http://prokr.org
    مكافحة حشرات بالرياض
    http://albyaan.com/insect-control-companies-riyadh/
    مكافحة حشرات بالمدينة
    http://elbassma.net/anti-insects-companies-al-madina/

    ReplyDelete
  3. Pretty! This has been an incredibly wonderful article. Thank you for providing this info.
    شركات كشف التسربات
    http://prokr.org
    شركة كشف تسربات بجدة
    http://prokr.com/water-leaks-detection-isolate-company-jeddah/
    شركة كشف التسربات بمكة
    http://albyaan.com/water-leaks-detection-companies-mecca/
    شركات كشف تسربات وعزل بالمنطقة الغربية
    http://abozahra.com/water-leaks-detection/jeddah-western-region-companies/

    ReplyDelete
  4. Very good post. I'm facing some of these issues as well..

    عقاري جدة
    http://3kary.com/
    شقق مفروشة بجدة
    http://3kary.com/property-status/monthly-apartments-for-rent/
    شقق عزاب بجدة
    http://3kary.com/property-status/apartments-bachelors/

    ReplyDelete

  5. Great article! We are linking to this great article on our site. Keep up the good writing.



    prokr.com




    3idat.com/jeddah/





    http://3kary.com/



    ReplyDelete