Android Application Development Environment Setup On Ubuntu

Do you want to develop you Applicaion on Ubuntu? Looking for how to Setup development environment? And your OS is Ubuntu? No worry you are now in right place. Just follow:

Step-1. Install JDK

sudo apt-get install sun-java6-jdk

If you get error related to “not found” then try following:

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk

Step-2. Goto your desktop menu and Install Eclipse IDE from there

Applications -> Ubuntu Software Center -> Get Software -> Developer Tools -> IDEs -> Eclipse

step-3. Open Terminal from Desktop menu Applications -> Accessories -> Terminal

sudo apt-get install eclipse-pde

Step-4. Download Android SDK and Extract it. Keep it in a place where ever you like. Location need be integrated with Eclipse next.

http://developer.android.com/sdk/index.html

Step-5. Open Eclipse from desktop menu Application -> programming -> Eclipse then Goto

Window -> Preferences -> Install/Update -> Available Software -> Add -- Name (ex: Android) -- Location (https://dl-ssl.google.com/android/eclipse/)

Add the link there.

step-6. In Eclipse Goto Help -> Install New Software -> From the dropdown select Android Repository -> Check “Developer Tools” -> Next -> Next -> Finish this.

You will probably ask for restarting Eclipse . Restart it.

step-7. Goto Window -> Preferences -> Android -> Browse your SDK location -> Apply, Ok

step-8. Goto Window -> See a new option created “Android SDK and AVD Manager” -> Available Packages -> Install Selected

Select your desired SDK or SDK’s , API , Documentation and Install those.

Now Enjoy your Android application developments.

Cheers!!

Set Application as Highest Priority Application (Symbian)

If you want to set your Application as Highest priority that is if you dont want your application to go to background even if a system procedure occurs like when an incoming call arrived…. you can just use this code in your appUi class’s constructor….

CEikonEnv::Static()->SetSystem( ETrue );
/* set application priority to foreground priority even if it goes to background*/
CEikonEnv::Static()->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
/*Make the application a high priority application*/
CEikonEnv::Static()->RootWin().EnableReceiptOfFocus( ETrue );
CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);

if this is not worked just let me know…

You can also set you application priorities like this

ECoeWinPriorityNeverAtFront

ECoeWinPriorityLow

ECoeWinPriorityNormal

ECoeWinPriorityMedium

ECoeWinPriorityHigh

ECoeWinPriorityFep

ECoeWinPriorityAlwaysAtFront

N.B. This code is tested on NOKIA S60 3rd Edition FP1 Device (E51)

Bring Application in Foreground (Symbian)

You Can bring your application in Foreground or send application to the Background

To Bring you application foreground just use this lines of code:

/*0xEBD12EE4 is application uid*/

TUid KMyAppUid = {0xEBD12EE4};
TApaTaskList taskList(CCoeEnv::Static()->WsSession());
TApaTask task = taskList.FindApp(KMyAppUid);
if (task.Exists())
{
task.BringToForeground();
}

To send application to the background just use

task.SendToBackground() 

instead of

task.BringToForeground()

N.B. This code is tested on NOKIA S60 3rd Edition FP1 Device (E51)

Track and Handle Incoming GSM Call (Symbian)

GsmCallTracker.h

class GSMCallTracker : public CActive
{
public:
/* Constructor/Destructor */
GSMCallTracker( CTelephony* aTelephony );
void StartCallTracking();
void WriteToFile(const TDesC& aFile,const TDesC16& aData);
void AnswerIncomingCall();
private:
/*
These are the pure virtual methods from CActive that
MUST be implemented by all active objects
*/
void RunL();
void DoCancel();
private:
CTelephony* iTelephony;
CTelephony::TCallId iCallId;
CTelephony::TCallStatusV1 iLineStatus;
CTelephony::TCallStatusV1Pckg iLineStatusPckg;
CTelephony::TCallStatus iLastInformedLineStatus;
/* this is need to answer incoming call */
TRequestStatus istatus1;
};

GsmCallTracker.cpp

_LIT(KFileName,"c:\\GSMCALL.txt");
int result = 100;
GSMCallTracker::GSMCallTracker( CTelephony* aTelephony )
: CActive( EPriorityStandard ),
iTelephony( aTelephony ),
iLineStatusPckg( iLineStatus )
{
CActiveScheduler::Add(this);
/*default constructor*/
iLineStatus.iStatus = CTelephony::EStatusUnknown;
iLastInformedLineStatus = CTelephony::EStatusUnknown;
}
void GSMCallTracker::StartCallTracking()
{
_LIT( KNotifyExamplePanic, "GSMCallTracker" );
__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyExamplePanic, 1 ));
Cancel();
iTelephony->NotifyChange( iStatus,
CTelephony::EVoiceLineStatusChange,
iLineStatusPckg );
SetActive();
}
void GSMCallTracker::RunL()
{
if(iStatus.Int()!=KErrNone)
{
StartCallTracking();
return;
}
switch(iLineStatus.iStatus)
{
case CTelephony::EStatusRinging:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusRinging "));
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
TRAPD(result, iTelephony->AnswerIncomingCall( iStatus, iCallId, CTelephony::EVoiceLine));
SetActive();
break;
}
case CTelephony::EStatusConnected:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusConnected "));
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iLineStatusPckg);
SetActive();
break;
}
case CTelephony::EStatusAnswering:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusAnswering "));
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iLineStatusPckg);
SetActive();
break;
}
case CTelephony::EStatusDisconnecting:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusDisconnecting "));
StartCallTracking();
break;
}
case CTelephony::EStatusIdle:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusIdle "));
StartCallTracking();
break;
}
default:
{
/* write your code here */
WriteToFile(KFileName, _L(" Default "));
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iLineStatusPckg);
SetActive();
break;
}
}
}
void GSMCallTracker::DoCancel()
{
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
}
void GSMCallTracker::WriteToFile(const TDesC& aFile,const TDesC16& aData1)
{
RFile ReadFil;
TBuf8<50>aData;
aData.Copy(aData1);
if(BaflUtils::FileExists(CCoeEnv::Static()->FsSession(),aFile))
User::LeaveIfError(ReadFil.Open(CCoeEnv::Static()->FsSession(),aFile,EFileWrite));
else
User::LeaveIfError(ReadFil.Create(CCoeEnv::Static()->FsSession(),aFile,EFileWrite));
CleanupClosePushL(ReadFil);
/* User::LeaveIfError(ReadFil.Write(aData)); */
TInt pos = 0;
TInt err = ReadFil.Seek( ESeekEnd , pos );
if( err == KErrNone )
{
User::LeaveIfError(ReadFil.Write(aData));
}
CleanupStack::PopAndDestroy(1);//ReadFile
}
void GSMCallTracker::AnswerIncomingCall()
{
WriteToFile(KFileName, _L(" Before AnswerIncomingCall "));
Cancel();
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
TRAPD(result, iTelephony->AnswerIncomingCall( istatus1, iCallId, CTelephony::EVoiceLine));
iTelephony->NotifyChange( iStatus,CTelephony::EVoiceLineStatusChange,iLineStatusPckg );
SetActive();
WriteToFile(KFileName, _L(" After AnswerIncomingCall "));
}

You can handle GSM call in keypress event too… just block some lines from Estatusringing in RunL() method…

there is no solution i have found yet for hang up the call wihtout Call ID in public SDK. Call ID you can get when you answer or Dialed the call. So if you want to reject an incoming call without answering you can apply this technique

RWsSession ws;
ws.Connect();
TRawEvent downEvent;
downEvent.Set(TRawEvent::EKeyDown, EStdKeyNo);
ws.SimulateRawEvent(downEvent);
User::After(50000);
TRawEvent upEvent;
upEvent.Set(TRawEvent::EKeyUp, EStdKeyNo);
ws.SimulateRawEvent(upEvent);
ws.Close();

But to use this you will need SwEvent capability…

And if you want to hang up an already answered call or a dialed call you can use this

iTelephony->Hangup(iStatus, iCallId);

Cheers!!

Finding Machine ID or Detect the Model of the Mobile (Symbian)

## Finding the Machine ID for a specific Mobile. Require to identify which mobile it is

Note that Machine ID is fixed for each model of Mobile Handsets

Required Header file: hal.h

Required Library:  hal.lib

Code:

TInt uid;
HAL::Get(HAL::EMachineUid, uid);

Finding the IMEI Number in Symbian C++

## Finding IMEI number of the Mobile

Required LIBRARY: etel3rdparty.lib

Required Capability: No

Header file: IMEIApp.h

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

class CIMEIApp : public CActive
{
private:
void ConstructL();
CTelephony* iTelephony;
CTelephony::TPhoneIdV1 iPhoneIdV1;
CTelephony::TPhoneIdV1Pckg iPhoneIdV1Pckg;

public:
CIMEIApp(TDes& aIMEI);
~CIMEIApp();
static void GetIMEI(TDes& aIMEI);
TDes& IMEI;

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

Cpp file: IMEIApp.cpp

#include "IMEIApp.h"

void CIMEIApp::GetIMEI(TDes&amp; aIMEI)
{
CIMEIApp* self= new (ELeave) CIMEIApp(aIMEI);
CleanupStack::PushL(self);
self-&gt;ConstructL();
CleanupStack::PopAndDestroy(self);
}

void CIMEIApp::ConstructL()
{
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this);

iTelephony-&gt;GetPhoneId(iStatus, iPhoneIdV1Pckg);
SetActive();
CActiveScheduler::Start();
}

CIMEIApp:: CIMEIApp(TDes&amp; imei): CActive(EPriorityStandard),IMEI(imei),iPhoneIdV1Pckg(iPhoneIdV1)
{
//default constructor
}

CIMEIApp::~CIMEIApp()
{
delete iTelephony;
iTelephony = NULL;
}

void CIMEIApp::RunL()
{
if(iStatus==KErrNone)
{
IMEI= iPhoneIdV1.iSerialNumber;
CActiveScheduler::Stop();
}
}

void CIMEIApp::DoCancel()
{
iTelephony-&gt;CancelAsync(CTelephony::EGetPhoneIdCancel);
}

just use:

TBuf<25> iIMEI;
CIMEIApp::GetIMEI(iIMEI);

Capturing Keys from Background or Foreground

## Capturing keys Background or Foreground

Here is an example for End Key (Red Key)

Library:

Capability: SWEvent

Header file: ForeGroundObserver.h

#include <w32std.h>
#include <APGWGNAM.H> //CApaWindowGroupName

/*class MFgrCallBack
{
public:
    virtual void ForegroundEventL(TUid aAppUid) = 0;
};*/

class CFgrObserver : public CActive
{

public:

static CFgrObserver* NewL(RWsSession& aWsSession/*,MFgrCallBack& aCallBack*/);
static CFgrObserver* NewLC(RWsSession& aWsSession/*,MFgrCallBack& aCallBack*/);
virtual ~CFgrObserver();

private:

CFgrObserver(RWsSession& aWsSession/*,MFgrCallBack& aCallBack*/);
void ConstructL();
void RunL();
void DoCancel();
void Listen();
private:
/*    MFgrCallBack&     iCallBack; */
RWsSession&     iWsSession;
RWindowGroup    iWg;

public:

TInt iEndKey1,iEndKey2 ;

};

Cpp file: ForeGroundObserver.cpp

#include "ForeGroundObserver.h"
#include "eikbtgpc.h"

CFgrObserver* CFgrObserver::NewL(RWsSession& aWsSession/*,MFgrCallBack& aCallBack*/)
{
CFgrObserver* self = CFgrObserver::NewLC(aWsSession/*,aCallBack*/);
CleanupStack::Pop(self);
return self;
}

CFgrObserver* CFgrObserver::NewLC(RWsSession& aWsSession/*,MFgrCallBack& aCallBack*/)
{
CFgrObserver* self = new (ELeave) CFgrObserver(aWsSession/*,aCallBack*/);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}

CFgrObserver::CFgrObserver(RWsSession& aWsSession/*,MFgrCallBack& aCallBack*/)
:CActive(EPriorityHigh),/*iCallBack(aCallBack),*/ iWsSession(aWsSession), iWg(aWsSession)
{
}

CFgrObserver::~CFgrObserver()
{
Cancel();
iWg.Close();

////////////
RWindowGroup& groupWin = CCoeEnv::Static()->RootWin();
groupWin.CancelCaptureKeyUpAndDowns( iEndKey1 );
groupWin.CancelCaptureKey( iEndKey2 );
///////////
}

void CFgrObserver::ConstructL()
{
CActiveScheduler::Add(this);

User::LeaveIfError(iWg.Construct((TUint32)&iWg, EFalse));
iWg.SetOrdinalPosition(-1);
iWg.EnableReceiptOfFocus(EFalse);

CApaWindowGroupName* wn=CApaWindowGroupName::NewLC(iWsSession);
wn->SetHidden(ETrue);
wn->SetWindowGroupName(iWg);
CleanupStack::PopAndDestroy();

User::LeaveIfError(iWg.EnableFocusChangeEvents());

Listen();
}

void CFgrObserver::RunL()
{
if (iStatus == KErrNone)
{
TWsEvent e;
iWsSession.GetEvent(e);
}

TInt wgid = iWsSession.GetFocusWindowGroup();

CApaWindowGroupName* gn;
gn = CApaWindowGroupName::NewLC(iWsSession, wgid);

///////////////
TUid appuid1= {0x20027DAE};
TUid appuid2= {0x100056CF};
/*   RWindowGroup wg  = iEikonEnv->RootWin(); */
RWindowGroup& wg = CCoeEnv::Static()->RootWin();
if(gn->AppUid() == appuid1)
{
/* We are in the foreground , so capture the keys */
if (iEndKey1 <=0)
{
iEndKey1= wg.CaptureKeyUpAndDowns( EStdKeyNo, 0, 0 );
}
if (iEndKey2 <=0)
{
iEndKey2 = wg.CaptureKey( EKeyNo, 0, 0 );
}
}
else if (gn->AppUid() == appuid2)
{
/* We are in the foreground , so capture the keys */
if (iEndKey1 <=0)
{
iEndKey1= wg.CaptureKeyUpAndDowns( EStdKeyNo, 0, 0 );
}
if (iEndKey2 <=0)
{
iEndKey2 = wg.CaptureKey( EKeyNo, 0, 0 );
}
}
else
{
/* We are in the background  , so cancel the capture keys */
if (iEndKey1 >0)
{
wg.CancelCaptureKeyUpAndDowns(iEndKey1);
iEndKey1 =0;
}
if (iEndKey2 >0)
{
wg.CancelCaptureKey(iEndKey2);
iEndKey2 = 0;
}
}
////////////////
/*   iCallBack.ForegroundEventL(gn->AppUid()); */

CleanupStack::PopAndDestroy(); // gn

if (iStatus != KErrCancel)
{

Listen();

}
}

void CFgrObserver::DoCancel()
{
iWsSession.EventReadyCancel();
}

void CFgrObserver::Listen()
{
iWsSession.EventReady(&iStatus);
SetActive();
}

Declare in AppUI header file:

CFgrObserver* iFgrObserver;
RWsSession      iWsSession;

Declare in AppUI cpp file:

In Destructor:

delete iFgrObserver;
iWsSession.Close();

In ConstructorL:

User::LeaveIfError(iWsSession.Connect());
iFgrObserver = CFgrObserver::NewL(iWsSession/*, *this*/);