Showing posts with label S60 API Samples. Show all posts
Showing posts with label S60 API Samples. Show all posts

Thursday, January 22, 2015

HOW TO ADD VOLUME BAR IN NAVIPANE?



SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
CEikStatusPane *iStatusPane = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
iNaviPane = (CAknNavigationControlContainer*) iStatusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
iNaviDecorator =iNaviPane->CreateVolumeIndicatorL(R_AVKON_NAVI_PANE_VOLUME_INDICATOR);
STATIC_CAST(CAknVolumeControl*,iNaviDecorator->DecoratedControl())->SetValue(10);
iNaviPane->PushL(*iNaviDecorator);

GLOBAL NOTE EXAMPLE



//changes in loc file
#define qtn_global_note_example_text "GLOBAL NOTE"
//add this line in .rss file
RESOURCE TBUF r_global_note_example
{
 buf = qtn_global_note_example_text;
}
HBufC* text = StringLoader::LoadLC(R_GLOBAL_NOTE_EXAMPLE);
CAknGlobalNote* globalInfoNote = CAknGlobalNote::NewLC();
globalInfoNote->ShowNoteL(EAknGlobalInformationNote,*text);
CleanupStack::PopAndDestroy( globalInfoNote );
CleanupStack::PopAndDestroy( text );

HOW TO SEARCH DEVICE THROUGH BLUETOOTH



coecntrl.h
es_sock.h
btdevice.h
bt_sock.h
btsdp.h
bttypes.h


struct TDeviceData
{
 THostName iDeviceName;
 TBTDevAddr iDeviceAddr;
 TUint iDeviceServicePort;
};


// Literals
_LIT(KBTLinkManagerTxt,"BTLinkManager");

TInquirySockAddr iAddr; //bluetooth.lib
TNameEntry iEntry;
TRequestStatus iStatus;
RSocketServ aSocketServ; //esock.lib
TProtocolDesc pdesc;
RHostResolver aResolver;

User::LeaveIfError(aSocketServ.Connect());
User::LeaveIfError(aSocketServ.FindProtocol(KBTLinkManagerTxt(), pdesc));
User::LeaveIfError(aResolver.Open(aSocketServ, pdesc.iAddrFamily, pdesc.iProtocol));

iAddr.SetIAC( KGIAC );
iAddr.SetAction(KHostResInquiryKHostResNameKHostResIgnoreCache);
aResolver.GetByAddress(iAddr, iEntry, iStatus);
User::WaitForRequest(iStatus);
if(iStatus==KErrNone)
{
 TDeviceData *devData = new (ELeave) TDeviceData();
 devData->iDeviceName = iEntry().iName;
 devData->iDeviceAddr =
 static_cast(iEntry().iAddr).BTAddr();
}

HOW TO TURN OFF BLUETOOTH

Description:
In Sym 3rd Edition, Blutooth can be controlled through central repositry(CRepository). KCRUidBluetoothPowerState is the repositry UID to controls bluetooth power state.
header Files
centralrepository.h, btserversdkcrkeys.h
CRepository* cr = CRepository::NewL( KCRUidBluetoothPowerState );
TInt value;
TInt BTerror;
cr->Get( KBTPowerState, value );
if(value==EBTPowerOn)
{
BTerror = cr->Set( KBTPowerState, EBTPowerOff);
}
Note: To verify the bluetooth power changes (implement notifier).

HOW TO TURN ON BLUETOOTH

Description:
In Sym 3rd Edition, Blutooth can be controlled through central repositry(CRepository). KCRUidBluetoothPowerState is the repositry UID to controls bluetooth power state.
HeaderFiles to include:
centralrepository.h, btserversdkcrkeys.h
Code for use:
CRepository* cr = CRepository::NewL( KCRUidBluetoothPowerState );
TInt value;
TInt BTerror;
cr->Get( KBTPowerState, value );
if(value==EBTPowerOff)
{
BTerror = cr->Set( KBTPowerState, EBTPowerOn);
}
Note: To verify the bluetooth power changes (implement notifier).

HOW TO GET NOTIFIED WHILE BT TURNED ON?

BtnotifierAPI.h - for KPowerModeSettingNotifierUid

Register with the notifer
RNotifier notifier;
User::LeaveIfError( notifier.Connect() );
TPckgBuf dummy(ETrue);
TPckgBuf reply(EFalse);
notifier.StartNotifierAndGetResponse(iStatus, KPowerModeSettingNotifierUid, dummy, reply);
if(!IsActive())
SetActive();

Note: Power changes will be notifed in RunL()

Cancel the notification request
notifier.CancelNotifier(KPowerModeSettingNotifierUid);
notifier.Close();

HOW TO CHANGE ACTIVE PROFILE?

Overview:
Profiles Engine API, part of the Extension plug-in package for S60 3rd Edition, provides the class MProEngEngine that can be used changd the active profile.
Description:
headerfiles
mproengengine.h, proengfactory.h, profile.hrh
library: ProfileEngine.lib
Code:
MProEngEngine* engine = ProEngFactory::NewEngineL();
CleanupReleasePushL(*engine);
TInt Activeprofile = engine->ActiveProfileId(); //Return the active profiles value
engine->SetActiveProfileL(EProfileSilentId); //changes the active profile to Silentmode
CleanupStack::PopAndDestroy(1);

Note:
SetActiveProfileL method can be called only by processes having WriteDeviceData capability.

HOW TO MAKE A CALL USING CTELEPHONY?

Description:
This label explains about how to make call using CTelephony.
APIs Information:
class CTelephony - By using this you can find information about phone and dial call, answer and control voice calls.
CTelephony::DialNewCall(TRequestStatus &aStatus, TDes8 &aCallParams, const TTelNumber &aTelNumber, TCallId &aCallId, const TPhoneLine aLine=EVoiceLine) const;

Usage:


CCallMaker* iCallmaker = new (ELeave)CCallMaker(*this); 
iCallmaker->ConstructL("Telephone number to be called");

//The class activate the call manager should derive from class MCallObserver and 
// shound implement the pure virtual function CallDialedL.

CallDialedL(TInt aError) 
{
 RDebug::Printf("CallDialedL = %d",aError);
 delete iCallmaker;
 iCallmaker = NULL;
}

//Observer class for call back.
class MCallObserver 
{ 
 public: 
 virtual void CallDialedL(TInt aError) = 0; 
};
//Implementst the call handling.
class CCallMaker : public CActive 
{
 public: 
 //Initialize the callback pointer 
 CCallMaker(MCallObserver& aObserver);
 //Initialize the call and make the active object to Active 
 void ConstructL(const TDesC& aNumber);
 ~CCallMaker();
 //From CActive Class
 private: 
 void RunL(); 
 void DoCancel();
 private: //Data
 MCallObserver& iObserver; 
 CTelephony* iTelephony; 
 CTelephony::TCallId iCallId; 
 CTelephony::TCallParamsV1 iCallParams; 
 CTelephony::TCallParamsV1Pckg iCallParamsPckg; 
};

//Definition
CCallMaker::~CCallMaker() 
{ 
 Cancel(); 
 delete iTelephony;
}

void CCallMaker::ConstructL(const TDesC& aNumber) 
{
 iTelephony = CTelephony::NewL(); 
 CTelephony::TTelNumber telNumber;
 telNumber.Copy(aNumber); 
 iCallId = CTelephony::EISVMaxNumOfCalls; 
 iCallParams.iIdRestrict = CTelephony::ESendMyId; 
 iTelephony->DialNewCall(iStatus, iCallParamsPckg, telNumber, iCallId); SetActive();
 iStatus = KRequestPending;
}

CCallMaker::CCallMaker(MCallObserver& aObserver): CActive(EPriorityNormal),iObserver(aObserver), iCallParamsPckg(iCallParams)
{ 
 CActiveScheduler::Add(this);
}
void CCallMaker::RunL() 
{ 
 iObserver.CallDialedL(iStatus.Int());
}

void CCallMaker::DoCancel() 
{ 
 iTelephony->CancelAsync(CTelephony::EDialNewCallCancel);
}

HOW TO SEND MESSAGE(SMS)

Description:
This label explains about how to send SMS.
Code Example:


//classes to be used to send SMS.
RSendAs iSendAs;
RSendAsMessage iSendAsMessage;

User::LeaveIfError(iSendAs.Connect());
iSendAsMessage.CreateL(iSendAs, KUidMsgTypeSMS);
iSendAsMessage.AddRecipientL("Recipient MobileNumber",RSendAsMessage::ESendAsRecipientTo);
iSendAsMessage.SetBodyTextL("Text to be sent"); 
iSendAsMessage.SendMessageAndCloseL();

/*This s to show information note for sending message.*/
HBufC* textResource = StringLoader::LoadLC(R_MESSAGE_SENT_SUCCESSFULLY); CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note with 
// textResource loaded with StringLoader.
informationNote->ExecuteLD( *textResource);
// Pop HBuf from CleanUpStack and Destroy it.
CleanupStack::PopAndDestroy( textResource );

HOW TO CHANGE STATUS PANE ICON

Description: 
This label explains about how to change the default staus pane provided by the s60 framework for UI Application.
Usage:
class CControlsAppContainer2;
Changes the Default Stauspane Icon:


_LIT( KIconFile, "z:\\resource\\apps\\Cotrols.mbm" ); //Path of the mbm file
ChangePaneIconL(KIconFile, EMbmCotrolsBitmap2/*Bitmap Image Id*/, EMbmCotrolsBitmap2_m/*Bitmap mask Image Id*/);

void CControlsAppContainer2::ChangePaneIconL(const TDesC& aIconFile, TInt aIndex, TInt aMask) 
{
 CEikStatusPane* StatusPane = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
 if (StatusPane )
 {
 CAknContextPane
 * ContextPane =
  (CAknContextPane*) StatusPane ->ControlL(TUid::Uid(EEikStatusPaneUidContext));
 if (ContextPane)
 {
  ContextPane->SetPictureFromFileL(aIconFile, aIndex, aMask);
 }
 }
}

Note: 
ContextPane->SetPictureToDefaultL(); //this function call will change the staus pane to default(provided by S60 UI Framework)

HOW TO CHANGE STATUS PANE TEXT

Description:
This label explains about how to change the default status pane (generally the application name) text provided by the s60 UI framework.
Usage:


CEikStatusPane* sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
if (sp)
{
 CAknTitlePane* TitlePane= STATIC_CAST(CAknTitlePane*,
 sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
 if (TitlePane)
 {
  TitlePane->SetTextL(aText); //Pass the text to be displayed in aText.
 }
}

Note:
To get back the default staus pane you can use the following API.
TitlePane->SetTextToDefaultL();

DRAW BITMAP IMAGE IN CONTAINER

Description: This label explains about, how to bring the image in view.
Step1: Symbian supports MBM format for image. (Convet image to MBM format)

class : CFbsBitmap

Code:
//path & name of the MBM file
_LIT(KMBMFileName1,"z:\\resource\\apps\\Example.mbm");
//Load the image
CFbsBitmap* Bitmap = new (ELeave) CFbsBitmap; TInt Err = Bitmap->Load(KMBMFileName1, EMbmWinamp24bit);
//Draw the image in 0,0 co-ordinates.
TSize bmpSizeInPixels=Bitmap->SizeInPixels();
TSize bmpPieceSize(bmpSizeInPixels.iWidth/2, bmpSizeInPixels.iHeight/2);
TRect bmpPieceRect(TPoint(0, 0), bmpPieceSize);
gc.BitBlt(TPoint(0, 0), Bitmap, bmpPieceRect);

HOW TO LAUNCH AN EXE?

RApaLsSession appSession;
User::LeaveIfError(appSession.Connect());
CleanupClosePushL(appSession);
TUid uid;
uid.iUid = 0xEC704FF7 ;//UID of the exe to be started

TApaAppInfo appInfo;
appSession.GetAppInfo(appInfo, uid);
CApaCommandLine* commandLine = CApaCommandLine::NewL();
CleanupStack::PushL(commandLine);
commandLine->SetExecutableNameL(appInfo.iFullName);

//commandLine->SetTailEndL(KArg); //this can be used to send parameter to the exe to be //launched
Error = appSession.StartApp(*commandLine);
RDebug::Printf("startApp() return Error: %d",Error);
CleanupStack::PopAndDestroy(2);

HOW TO KILL AN EXE?


TFindProcess process(_L("*"));//NAME PATTERN
TFullName aResult;
TBuf<32> aPtr(_L("ATCamera"));
//GET ALL THE PROCESS NAME WHICH MET'S THE NAME PATTERN
while(process.Next(aResult)==KErrNone)
{
 TInt pId= aResult.Find(aPtr); //FIND THE ATCAMERA.EXE
 RDebug::Printf("matches the name %d",pId);
 if(pId != KErrNotFound)
 {
 RProcess myProcess;
 myProcess.Open(process);
 myProcess.Kill(0);
 myProcess.Close();
 }
}

HOW TO USE RPROPERTY?


//Declaration of RProperty with specific UID
const TUid KExampleProperty = {0x101F17A8};
enum TExamplePropertyKeys
{
 EIntProperty,
 EStrProperty
};

//Definition of the Property
TInt ret=RProperty::Define(KExampleProperty,EIntProperty,RProperty::EInt);
if (ret != KErrNone)
{
 User::LeaveIfError(ret);
 RDebug::Printf("ErrValue is: %d",ret);
}

//Set the value of the property value.
ret=RProperty::Set(KTsmdProperty,ETsmdProperty,0);
RDebug::Printf("ErrValue is: %d",ret);
if (ret != KErrNone)
{
 User::LeaveIfError(ret);
 RDebug::Printf("ErrValue is: %d",ret);
}

//Get the property value.
TInt Err;
TInt propertyvalue;
Err = RProperty::Get(KExampleProperty,EIntProperty,propertyvalue);
if(Err!=KErrNone)
RDebug::Printf("TCmdKEY::StartTestMode Get Err value: %d",Err);