Symbian3/SDK/Source/GUID-79CFCC01-7418-5ECA-AF65-1DCAD97AA7A6.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE task
  PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task xml:lang="en" id="GUID-79CFCC01-7418-5ECA-AF65-1DCAD97AA7A6"><title>Battery Information Tutorial</title><shortdesc>This tutorial describes the steps to retrieve the battery information from the device. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> <steps id="GUID-F83E8419-F662-5A61-9323-0D75C9908170"> <step id="GUID-7B5254D8-C262-519B-B3FF-D57A2D7B6243"><cmd/><info>create a new instance of <xref href="GUID-97D402C8-B4B7-385A-92B3-D3FCC0CA575A.dita"><apiname>CTelephony</apiname></xref> with active objects </info> </step> <step id="GUID-0605977A-E621-5C84-AC94-005D21BD2E95"><cmd/><info>use <xref href="GUID-97D402C8-B4B7-385A-92B3-D3FCC0CA575A.dita"><apiname>CTelephony::GetBatteryInfo()</apiname></xref> to get the battery information </info> </step> <step id="GUID-F8997D43-283B-5879-8BD5-AC97DE965229"><cmd/><info>the function returns the information in <xref href="GUID-97D402C8-B4B7-385A-92B3-D3FCC0CA575A.dita"><apiname>CTelephony::TBatteryInfoV1</apiname></xref>  </info> <info>The result contains the battery charge level and the battery status. </info> </step> <step id="GUID-C232F8FF-D1AE-56ED-A608-341892D7716A"><cmd/><info>use <xref href="GUID-97D402C8-B4B7-385A-92B3-D3FCC0CA575A.dita"><apiname>CTelephony::EGetBatteryInfoCancel</apiname></xref> to cancel the asynchronous function </info> </step> <step id="GUID-DD9ABED8-3992-502F-8913-200029FF2B08"><cmd/><info>use <xref href="GUID-97D402C8-B4B7-385A-92B3-D3FCC0CA575A.dita"><apiname>CTelephony::EBatteryInfoChange</apiname></xref> to get the notification of any changes to the battery information </info> </step> <step id="GUID-58FE9960-9B4E-56F7-B36D-3FACD884E8A1"><cmd/><info>pass the enumeration <xref href="GUID-97D402C8-B4B7-385A-92B3-D3FCC0CA575A.dita"><apiname>CTelephony::EBatteryInfoChangeCancel</apiname></xref> to cancel the notification request. </info> </step> </steps> <example id="GUID-A61FA77E-BD0D-5A31-B558-DA98252B6717"><title>Battery information example</title> <codeblock id="GUID-D97E8177-1EE7-579B-AADB-4F3B084CD539" xml:space="preserve">#include &lt;e32base.h&gt;
#include &lt;Etel3rdParty.h&gt;

class CClientApp : public CActive
  { 

private:
    CTelephony* iTelephony;
    CTelephony::TBatteryInfoV1 iBatteryInfoV1;
    CTelephony::TBatteryInfoV1Pckg iBatteryInfoV1Pckg;

public:
    CClientApp(CTelephony* aTelephony);
    void SomeFunction();

private:
    /*
       These are the pure virtual methods from CActive that  
       MUST be implemented by all active objects
       */
    void RunL();
    void DoCancel();
   };

CClientApp::CClientApp(CTelephony* aTelephony)
    : CActive(EPriorityStandard),
      iTelephony(aTelephony),
      iBatteryInfoV1Pckg(iBatteryInfoV1)
    {
    //default constructor
    }

void CClientApp::SomeFunction()
    {
    iTelephony-&gt;GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
    SetActive();
    }

void CClientApp::RunL()
    {
    if(iStatus==KErrNone)
       {
       CTelephony::TBatteryStatus batteryStatus = iBatteryInfoV1.iStatus;
       TUint chargeLevel = iBatteryInfoV1.iChargeLevel;
       }
    }

void CClientApp::DoCancel()
    {
    iTelephony-&gt;CancelAsync(CTelephony::EGetBatteryInfoCancel);
    }</codeblock> </example> </taskbody></task>