Symbian Security Studio

About symbian software programming ,security analysis and other things about symbian.

Monday, October 1, 2007

Symbian Programming - Bluetooth


Symbian Programming - Sending files via Bluetooth
I first tried using the lower level OBEX functionality to send files but I couldn't get that working with my laptop. Not even the supplied examples (that do work with another phone) worked with the laptop. So I'm using the CSendAppUi class.
The CSendAppUi only works with graphical applications, since it has to be put in a menu and used from the menu choice. Here's how it works:
Use the sendui.h header and link against SENDUI.LIB
Use the sendnorm.rsg resource header to get the resource ID used
Create an instance of the CSendAppUi class in your AppUi. Initialized the class with the command id you want to use: sendui=CSendAppUi::NewL(Econtext_logCmdSendAppUi, NULL);
The command id should be chosen so that there are free ids after it, since the CSendAppUi will return one of several ids that begin with the given, depending on the type of communications chosen.
When the menu you want to show the Send command in is activated, call sendui->DisplaySendMenuItemL(*aMenuPane, 1,
TSendingCapabilities (0, 100000, 0));
in your DynInitMenuPaneL(). We want to send largish files but no other content, so we initialize the TSendingCapabilities with bodysize 0 and no flags, but with at least 100k available for attachments.
When the actual SendUi menu (R_SENDUI_MENU) is activated, call sendui->DisplaySendCascadeMenuL(*aMenuPane);
in your DynInitMenuPaneL().
If the user chooses one of the send menu types, they are first presented with the necessary options (for example Bluetooth device selection). After that your HandleCommandL will be called with a command id larger than the one you gave when initializing the object. So in your HandleCommandL do something like this: switch ( aCommand )
{
default:
if (aCommand > Econtext_logCmdSendAppUi) {

CDir* dir;
_LIT(dirname, "c:\\system\\apps\\context_log\\log*.txt");
User::LeaveIfError(fsSession.GetDir(dirname, KEntryAttNormal,
ESortByName, dir));
CleanupStack::PushL(dir);
CDesC16ArrayFlat *array = new (ELeave) CDesC16ArrayFlat(dir->Count());
CleanupStack::PushL(array);
TBuf<256> filen;
for (int i=0; iCount(); i++) {
filen=(TText*)L"c:\\system\\apps\\context_log\\";
filen.Append((*dir)[i].iName);
TEntry fe;
if (fsSession.Entry(filen, fe)==KErrNone && fe.iSize>0) {
array->AppendL(filen);
}
}

sendui->CreateAndSendMessageL (aCommand, 0, array);
CleanupStack::PopAndDestroy(2); // dir, array
}
break;
}
Things to note:
You cannot send files that are open, even if you have opened them in shared mode.
You cannot send files of size 0
At least I don't know of a way of knowing whether the sending succeeded or not programmatically. The user will see an error message from the CSendAppUi class if something goes wrong.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home