×
Namespaces

Variants
Actions

Detect the file name when a new image/video clip has been taken from the built-in Camera application

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): N73, N95, E72, 5800XM, N8
Compatibility
Platform(s): Symbian
Article
Keywords: RProperty KPSUidCamcorderNotifier KCamLatestFilePath
Created: chenziteng (06 Aug 2010)
Last edited: hamishwillee (30 May 2013)

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:

  1. Build the application for WINSCW and then start it on emulator
    Emulator01.PNG
  2. Start the Camera application, and then capture a picture
    Emulator02.PNG Emulator03.PNG

When the capturing/processing is done you will see a global note shows the name of the captured image. Emulator04.PNG

For S60 devices:

  1. Build the application for target and then sign the sis (with a certificate that can grant WriteDeviceData capability)
  2. 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)

References

Forum discussion

This page was last modified on 30 May 2013, at 07:33.
144 page views in the last 30 days.
×