×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Notification for change in battery level

    Hi,

    I am coding an application that keeps track of the battery level (KHWRMBatteryLevel) and logs every event for the change in the battery level using P&S API.

    The problem is... the application is getting notified when the battery level goes down(e.g from 5 to 4). But when the charger is plugged in and the battery level increases(e.g. from 4 to 5), there is no notification(i.e. no logs). Interestingly, the app gets notification immediately after the charger is disconnected.

    How to get notification while charging?
    Kindly clarify.

    The code is as follows:
    ---------------------------------------------------------
    RProperty batProp;
    TInt batLevel;
    batProp.Attach(KPSUidHWRMPowerState, KHWRMBatteryLevel, batLevel);
    batProp.Get(batLevel);
    batProp.Subscribe(myStatus);
    ...
    ...

    //The intention is to capture and log every "battery level change" event.
    void MyClass::RunL()
    {
    batProp.Get(batLevel);
    WRITELOG("battery level changed: %d", batLevel);
    batProp.Subscribe(myStatus); // resubscribe
    }
    ------------------

    Logs:

    battery level changed: 3
    //after a while
    battery level changed: 2
    //after a while
    battery level changed: 1

    //charger plugged in

    // no notification for a long time when the battery is charging and the level is actually increasing...

    //once the charger is disconnected
    battery level changed: 4

  2. #2
    Registered User
    Join Date
    Apr 2009
    Posts
    29

    Re: Notification for change in battery level

    hi,all

    I encounter the same issue when I try to get notify when the phone is in charging status.

    except that the discriptions of venunet's post.

    I found I can get the notify when the phone is in Full Power status although connecting the charger.

    it also say that we only can get the notify when the phone need to get the battery level to display the level bars in screen.

    I tried to resovle it with RProperty, NotifyChange, RTimer(every interval to get the RProperty), but all are failed.

    So I guess that the server do not complete your request to run your RunL function, neither change the battery level(it maybe the reason why I get the same value with the Rtimer)if phone is in charging status except of Full status.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    India
    Posts
    184

    Re: Notification for change in battery level

    hello,

    u can use CTelephony apis to get Battery Level and notification changed
    // iTelephony = CTelephony::NewL();
    //CTelephony::TBatteryInfoV1Pckg iBatteryInfoV1Pckg;
    //CTelephony::TBatteryInfoV1 iBatteryInfoV1;

    //implement one function
    if(iTelephony && !IsActive())
    {
    iGettingBattery = ETrue;
    iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
    SetActive();
    }


    ///In RunL()
    //iObserver---implements observer class
    iObserver.BatteryLevelL(iBatteryInfoV1.iChargeLevel,iBatteryInfoV1.iStatus);
    if(iStatus != KErrCancel)
    {
    iTelephony->NotifyChange(iStatus,CTelephony::EBatteryInfoChange,
    iBatteryInfoV1Pckg);
    SetActive();
    }
    iGettingBattery = EFalse;

    //in Docancel
    if(iGettingBattery)
    iTelephony->CancelAsync(CTelephony::EGetBatteryInfoCancel);
    else
    iTelephony->CancelAsync(CTelephony::EBatteryInfoChangeCancel);


    IN BatteryLevelL() function of the observer class you will get the Battery level........

    Regards
    PRANAY

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Notification for change in battery level

    more then one example in wiki refer to them http://wiki.forum.nokia.com/index.ph...xt=Search+Wiki

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    29

    Re: Notification for change in battery level

    Yes, I try to use this mothod to get the notification for battery level change in charging status. but failed.

    I can not get the notify for level upgrate when in charging status. but can get the level going down change.

    my english is not very well, so i think you maybe not understand my means.

    the code as following:
    //a function will be run when new a instance
    {
    iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
    SetActive();
    }


    ///In RunL()
    if(iStatus != KErrCancel)
    {
    iTelephony->NotifyChange(iStatus,CTelephony::EBatteryInfoChange,
    iBatteryInfoV1Pckg);
    int result = iBatteryInfoV1Pckg.iChargeLevel;
    //the value of result is my wanted result

    SetActive();
    }

Similar Threads

  1. Detecting battery level with Javaphone API
    By cassioli in forum Mobile Java General
    Replies: 17
    Last Post: 2007-03-19, 20:16
  2. To check Battery charge Level
    By abernues in forum Symbian
    Replies: 5
    Last Post: 2006-02-27, 18:23
  3. BT GPS Battery level query
    By stephenclifton in forum Bluetooth Technology
    Replies: 1
    Last Post: 2005-08-22, 09:52
  4. 3100 and wrong battery charge level
    By vastar in forum General Development Questions
    Replies: 0
    Last Post: 2004-06-10, 06:29
  5. Battery level
    By nanard in forum Symbian
    Replies: 5
    Last Post: 2003-12-20, 13:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •