Thursday, September 27, 2007

Easiest way to query Access Point (IAP)

void CAppView::AccessPointL()
{
iConnOK=EFalse;

CApSettingsHandler* settingsHandler = CApSettingsHandler::NewLC(
ETrue,
EApSettingsSelListIsPopUp ,
EApSettingsSelMenuSelectNormal,
KEApIspTypeAll,
EApBearerTypeAll,
KEApSortNameAscending);

TUint32 originallyFocused(0);
// 0 is not valid IAP id. Failed if 0 after RunSettingsL().
TUint32 selectedIap(0);

// Show the dialog
settingsHandler->RunSettingsL(originallyFocused, selectedIap);

// The CApUtils API is deprecated/removed, the following code can be
used
// to convert the WapAP Id to IAP Id
if (selectedIap)
{
CCommsDatabase* db = CCommsDatabase::NewL();
CleanupStack::PushL(db);

CCommsDbTableView* wapTable;
wapTable = db->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT),
TPtrC(COMMDB_ID), selectedIap );
User::LeaveIfError( wapTable->GotoFirstRecord() );

TBuf<100> wapBearer;
wapTable->ReadTextL(TPtrC(WAP_CURRENT_BEARER), wapBearer);

if ( wapBearer == TPtrC(WAP_IP_BEARER) )
{
CCommsDbTableView* bearerTable;
bearerTable = db->OpenViewMatchingUintLC( TPtrC(wapBearer),
TPtrC(WAP_ACCESS_POINT_ID),
selectedIap );
User::LeaveIfError( bearerTable->GotoFirstRecord() );
bearerTable->ReadUintL(TPtrC(WAP_IAP), iIap );
CleanupStack::PopAndDestroy( bearerTable ); // bearerTable
}
else
{
User::Leave( KErrInvalidBearerType );
}
CleanupStack::PopAndDestroy(2); // db, wapTable,
}
else
{
iIap = 0;
}

CleanupStack::PopAndDestroy(settingsHandler);

if(!iIap)
{
iConnOK=EFalse;
}
else
{
iConnOK=ETrue;
}
}


Header Files : ApSettingsHandlerUI.h
Link against : apsettingshandlerui.lib
Installing sis file programmatically


RFile rFile;
RApaLsSession lsSession;
User::LeaveIfError(lsSession.Connect());
CleanupClosePushL(lsSession);
TThreadId threadId;

_LIT(KMyCertFile, "c:\\data\\app.sis");

if(BaflUtils::FileExists(CEikonEnv::Static()->FsSession(), KMyCertFile))
{
User::LeaveIfError(rFile.Open(CEikonEnv::Static()->FsSession(), KMyCertFile, EFileRead));
}

lsSession.StartDocument(rFile, threadId, NULL);
lsSession.ClearFsSession();
lsSession.Close();

Monday, September 24, 2007

How to prevent build-in camera application to be autolaunched

If your phone has a camera, nomrally if you open the camera cover{at least in my N70}, there will be a build-in app to be launched to captrue phones. But when you write your own camera apps, you might not want the build-in app to be launched, how to do this?

The theory is quite simple, camera cover open/close event is actually a KeyEvent, if you can capture this KeyEvent which window server dispatchs inside your application, you can prevent the default app being launched. Here's how:
void CHelloWorldAppUi::HandleForegroundEventL( TBool aForeground )
{
if( aForeground ) // switch to the foreground
{
iForeground = ETrue;
iOpenCameraKey = iEikonEnv->RootWin().CaptureKey( EKeyDevice1D, 0, 0 );
}
else
{
iForeground = EFalse;
iEikonEnv->RootWin().CancelCaptureKey( iOpenCameraKey );
}
}



It doesn't make sense if you capture this KeyEvent all the time, so I capture the key when my app is in foreground, release the key when my app is in background. So the default could be autostarted when this app is in backgrond.
How to convert HBuf to TBuf

_LIT(KSomeText, "Symbian");

HBufC* heapBuffer=HBufC::NewLC(15);
*heapBuffer = KSomeText;
TBuf<15> buffer(*heapBuffer);
CleanupStack::PopAndDestroy( heapBuffer );

Sunday, September 23, 2007

Hiding Your Application from task list

If you want to hide the application from the system task list add this method to the document class:
void CApplicationDocument::UpdateTaskNameL(CApaWindowGroupName* aWgName)
{
CAknDocument::UpdateTaskNameL(aWgName);
aWgName->SetHidden(ETrue);
}
or put in this code:
CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
Restart Phone With Low CAPABILITY

RWsSession iWs;
User::LeaveIfError(iWs.Connect());
TWsEvent e;
e.SetType(EEventPointer);
iWs.SendEventToOneWindowGroupsPerClient(e);
iWs.SendEventToAllWindowGroups( e);
Lock phone from code

RAknKeyLock keyLock;
User::LeaveIfError(keyLock.Connect());
CleanupClosePushL(keyLock);
keyLock.EnableKeyLock();
keyLock.Close();
CleanupStack::PopAndDestroy();

How can I determine the application language at run time?

The current language the application is using to display its UI can be retrieved with
TLanguage lang = CEikAppUi::ApplicationLanguageL();
For a non-localized application, this value is TLanguage::ELangNone (0xFFFF).
Note that this value may be different from the language returned by
User::Language();
which represents the language of the current locale (system-wide setting).

Thursday, September 06, 2007

Trolltech's "Green Phone" stack architecture

Trolltech, best known for development tools and Linux application stacks for phones and other mobile devices, will ship an "open" Linux-based phone in September,2006. The "Greenphone" features a user-modifiable Linux OS, and is meant to jumpstart a third-party native application ecosystem for Linux-based mobile phones.




Wednesday, September 05, 2007

Get cell broadcast

Header file
#ifndef __CBUTIL_H__
#define __CBUTIL_H__

#include <e32base.h>
#include <Etel3rdParty.h>

#include <etelmm.h>
#include <etel.h>
#include <etelmmcs.h>
#include <flogger.h>
#include <csmshandler.h>

class CCBUtil : public CActive
{
public:
CCBUtil();

static CCBUtil* NewL();

void ConstructL();

~CCBUtil();

private:
void RunL();

void DoCancel();

private:
RFileLogger iLog;

TRequestStatus iReqStatus;

RTelServer iServer;

RMobilePhone iPhone;

RMobileBroadcastMessaging iBroadcastMsg;

TBuf8<88> iGsmMsgdata;

CSmsHandler* iSmsHandler;

};

#endif // __CBUTIL_H__

Source File
#include "cbutil.h"
#include <eikenv.h>
#include <Etelmm.h>
#include <Etel3rdparty.h>
#include <stdio.h>

_LIT(KGsmModuleName,"phonetsy.tsy");

CCBUtil::~CCBUtil()
{
Cancel();
iPhone.Close();
iServer.UnloadPhoneModule(KGsmModuleName);
iServer.Close();
iLog.CloseLog();
iLog.Close();
}

CCBUtil* CCBUtil::NewL()
{
CCBUtil* self = new (ELeave) CCBUtil();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}


void CCBUtil::ConstructL()
{
RTelServer::TPhoneInfo iPhoneInfo;
iServer.Connect();
iServer.LoadPhoneModule(KGsmModuleName);
TInt enumphone;
User::LeaveIfError(iServer.EnumeratePhones(enumphone));
if (enumphone < 1)
{
User::Leave(KErrNotFound);
}
User::LeaveIfError(iServer.GetPhoneInfo(0, iPhoneInfo));
User::LeaveIfError(iPhone.Open(iServer,iPhoneInfo.iName));
iBroadcastMsg.Open(iPhone);
RMobileBroadcastMessaging::TMobileBroadcastAttributesV1 iAttrInfo;
TPckg<RMobileBroadcastMessaging::TMobileBroadcastAttributesV1> iDes(iAttrInfo);
iBroadcastMsg.ReceiveMessage(iStatus,iGsmMsgdata,iDes);
SetActive();
}

CCBUtil::CCBUtil()
: CActive(EPriorityNormal)
{
CActiveScheduler::Add(this);
}

void CCBUtil::RunL()
{
if(iStatus==KErrNone)
{
RFs fs;
fs.Connect();
RFile file;
TBuf<32> aFileName = _L("C:\\log.txt");
fs.Delete(aFileName);
file.Replace(fs,aFileName,EFileWrite);
file.Write(iGsmMsgdata);
file.Close();
fs.Close();

FILE* fp;
fp = fopen("c:\\log.txt","rb");

char locationString[94];
char cbuf;
int char_cnt = 0;
unsigned int bb = 0;

unsigned char ur, curr, prev = 0;
int cnt = 0;
for ( cnt = 0; cnt < 6; cnt++)
fread(&cbuf, 1, 1, fp);

while(fread(&cbuf,1,1,fp))
{
unsigned char aa = (1<< (7 -bb%7))-1;
ur = cbuf & aa;
ur = (ur << (bb)) | prev;
curr = cbuf &(0xff ^ aa);
curr = curr >>(7-bb);
prev= curr;
if(ur == 0xd)
{
break;
}

locationString[char_cnt] = ur;
bb = ++bb % 7;
char_cnt++;
if ( bb== 0 )
{
locationString[char_cnt++] = prev;
prev =0;
}
}

locationString[char_cnt] = '\0';
fclose(fp);
int len = 0;
while (locationString[len] != NULL )
len++;

HBufC* nameHeap = HBufC::NewLC(len);
TPtr namePtr(nameHeap->Des());
TBuf<250> messageText;

for (int i = 0; i < len; i++)
namePtr.Append((TChar)locationString[i]);

messageText.Copy(namePtr);

CAknInformationNote* informationNote = new ( ELeave )
CAknInformationNote;
informationNote->ExecuteLD(messageText);

CleanupStack::PopAndDestroy(nameHeap);
}
else
{
CAknInformationNote* informationNote = new ( ELeave )
CAknInformationNote;
informationNote->ExecuteLD(_L("Error :p"));
}
iBroadcastMsg.Close();
}

void CCBUtil::DoCancel()
{
}

Yes, i admit that the above code does not work every time. If you have some fix to above code please send the fix to me at my email id skumar.mobiledev@gmail.com

Saturday, September 01, 2007

How to restart device pragmatically


enum TSWStartupReason
{
// Normal startup reasons (100..149)

// Nothing set the (default value).
ESWNone = 100,

// Restore Factory Settings (Normal)
ESWRestoreFactorySet = 101,

// Language Switched
ESWLangSwitch = 102,

// Warranty transfer
ESWWarrantyTransfer = 103,

// Possibly needed for handling power off & charger connected use case.
ESWChargerConnected = 104,

// Restore Factory Settings (Deep)
ESWRestoreFactorySetDeep = 105
};

class SysStartup
{
public:
IMPORT_C static TInt ShutdownAndRestart(const class TUid& aSource, TSWStartupReason aReason);
};

Implementation

TUid uid = {0x};
SysStartup::ShutdownAndRestart( uid, ESWNone);


stats counter