Up to: Mika Raento's Symbian Programming pages

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:

  1. Use the sendui.h header and link against SENDUI.LIB
  2. Use the sendnorm.rsg resource header to get the resource ID used
  3. 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.
  4. 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.
  5. When the actual SendUi menu (R_SENDUI_MENU) is activated, call
    		sendui->DisplaySendCascadeMenuL(*aMenuPane);
    
    in your DynInitMenuPaneL().
  6. 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; i<dir->Count(); 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:


Mika Raento, mikie(at)iki.fi