Detect the file name when a new image/video clip has been taken from the built-in Camera application
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Overview
This article describes how to get an event notification when a new image/video clip has been taken from the built-in Camera application, and then how to fetch the file name from the event.
Solutions
When a new image/video clip has been captured (and saved to a file), the S60 Camera application will broadcast the file name by a Publish&Subscribe property. This can be used to get the file name when the captured image is saved to file or when the video clip recording complete.
That means we just need to use an Active Object to observe the property for the full path of the last camera file, see the code snippet below:
Step 1: Before using the property first try to define it, for the property may not have been defined yet. Note that the application needs to have WriteDeviceData capability because the property UID is not the same with its process SID.
// CameraFileObserver.cpp
...
// UID and key copied from the S60 Camera application source code
const TUid KPSUidCamcorderNotifier = {0x101F882E};
const TUint32 KCamLatestFilePath = 0x00000001;
...
void CCameraFileObserver::ConstructL()
{
// WriteDeviceData if the UID is not the SID of the process
TInt err = RProperty::Define(KPSUidCamcorderNotifier, KCamLatestFilePath, RProperty::ELargeText);
if(!((err==KErrNone)||(err==KErrAlreadyExists)))
{
User::LeaveIfError(err);
}
...
}
...
Step 2: Now we can attach to the property and then subscribe for the event.
// CameraFileObserver.cpp
...
void CCameraFileObserver::ConstructL()
{
...
err = iProperty.Attach(KPSUidCamcorderNotifier, KCamLatestFilePath);
User::LeaveIfError(err);
}
...
void CCameraFileObserver::Start()
{
Cancel(); // Cancel any request, just to be sure
iProperty.Subscribe(iStatus);
SetActive(); // Tell scheduler a request is active
}
Step 3: When there is a new camera file the AO::RunL() will be called, and then we use RProperty::Get() to get the file name (with full path)
// CameraFileObserver.cpp
...
void CCameraFileObserver::RunL()
{
TInt err = iStatus.Int();
iProperty.Subscribe(iStatus);
SetActive(); // Tell scheduler a request is active
if(err==KErrNone)
{
TFileName fn;
GetLastFileL(fn);
iObserver.NewCameraFileL(fn);
}
}
...
void CCameraFileObserver::GetLastFileL(TFileName& aFileName)
{
TInt err = RProperty::Get(KPSUidCamcorderNotifier, KCamLatestFilePath, aFileName);
User::LeaveIfError(err);
}
The observer can then do something to the file, in this example we simply show the file name in a note but more complex use cases can be implemented, for example an utility software may upload the file to a remote drive or the user's blog.
...
void CKJASDFSGJMAppUi::NewCameraFileL(const TFileName& aFileName)
{
// TODO: show the file name
CAknGlobalNote* gn = CAknGlobalNote::NewLC();
gn->ShowNoteL(EAknGlobalInformationNote, aFileName);
CleanupStack::PopAndDestroy(gn);
}
...
Example
Full example: File:KJASDFSGJM(LastCameraFile).zip
The example can be built on S60 5th Edition SDK and has been tested first on the S60 5th Edition emulator, and then on a series of S60 devices, including N73 (based on S60 3rd Edition), N95 (based on S60 3rd Edition FP1), E72 (based on S60 3rd Edition FP2), 5800 XM (based on S60 5th Edition) and N8 (based on Symbian^3). We have a good reason to believe that the trick works for all Nokia S60 3rd Edition to Symbian^3 devices, but don't take it for granted that it will also works on other manufactures' S60 phones. For example it might not work on Sony Ericsson U1i/U5i/U8i because on those phones the S60 Camera application has been replaced by a Sony Ericsson proprietary Camera application.
How to use:
For S60 5th Edition emulator:
- Build the application for WINSCW and then start it on emulator
- Start the Camera application, and then capture a picture
When the capturing/processing is done you will see a global note shows the name of the captured image.
For S60 devices:
- Build the application for target and then sign the sis (with a certificate that can grant WriteDeviceData capability)
- Install the signed sis on target and then start it, and then start the Camera application and capture a picture or video clip
When the capturing/saving/recording is done you will see a global note shows the name of the captured image/recorded video clip. (see the screen recordings in the example \docs folder)


how to set the i
CLTSchwarz - QT
I'd like to see how to put this code into QT. Could this be updated and used as an example of using Symbian in QT?CLTSchwarz 10:00, 1 May 2012 (EEST)
This page seems to be getting lots of hits lately! I thought I'd add this info for anyone looking into this: http://www.developer.nokia.com/info/sw.nokia.com/id/d34673cd-50fc-4b22-887c-869e1167e81f/Camera_Guide.html I haven't tried it out yet but Part 6 shows how to get the captured image path - but your app has to open the camera first. Perhaps hijack the camera button?