Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Listening a specific accessory connected/disconnected notifications

From Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: Accessory Monitoring API, CAccMonitor, RConnectedAccessories, CAccMonitorInfo, KAccMonHeadset, KAccMonWired
Created: Damavik (02 Nov 2008)
Last edited: hamishwillee (08 Feb 2012)

The Accessory Monitoring API interface offers accessory information about connected accessories. This API is meant to be used by clients that need to access information about connected accessories or clients that need notifications about accessories that connect/disconnect to the device. This API can be accessed by all S60 clients. The API provides stand-alone implementation units that are used by the client and the API provides information about the devices hardware resources.

Contents

Overview

Accessory connected/disconnected notifications can be listened with the StartListeningL() method of the CAccMonitor. Connection notifications in client side are received from the MAccMonitorObserver class. Thus client must implement this interface. Connection notifications are received through the ConnectedL() method and disconnection notifications are received through the DisconnectedL() method.

One of the use case of handling connected/disconnected notifications is sending application background/foreground on connection/disconnection events correspondingly. For example, music player application could be brought to foreground on headset connection event.


MMP file

LIBRARY accmonitor.lib
CAPABILITY could be self-signed

Header file

#include <accmonitor.h>
...
class CAccMonitorTest: public MAccMonitorObserver, ...
{
...
public:
CAccMonitorTest();
void ConstructL();
 
private:
void ConnectedL(CAccMonitorInfo* aAccessoryInfo);
void DisconnectedL(CAccMonitorInfo* aAccessoryInfo);
 
private:
// Instance of the connected accessory. The content of the pointer passed to ConnectedL()/DisconnectedL() must be copied to this value (with CopyL()),
// because the original pointer is distroyed after mentioned methods have been called.
CAccMonitorInfo* iAccessoryInfo;
};

Source file

Start listening of headset connected/disconnected notifications:

void CAccMonitorTest::ConstructL()
{
...
CAccMonitor* accMonitor = CAccMonitor::NewLC();
RConnectedAccessories array;
CleanupClosePushL(array);
accMonitor->GetConnectedAccessoryL(array);
 
if(accMonitor->IsObserving())
{
// Iterate through available accessories
for (TInt i = 0; count != i; i++)
{
if( array[i]->AccDeviceType() == KAccMonHeadset)
{
// Start observing of headset connected/disconnected notifications
accMonitor->StartObservingL(this, array[i]);
break;
}
}
}
 
CleanupStack::PopAndDestroy(&array);
CleanupStack::PopAndDestroy(accMonitor);
...
}

Handling connected/disconnected notifications:

void CAccMonitorTest::ConnectedL(CAccMonitorInfo* aAccessoryInfo)
{
// Reserve memory for the accessory information instance if necessary
if (!iAccessoryInfo)
iAccessoryInfo = CAccMonitorInfo::NewL();
// Otherwise just reset accessory information instance
else
iAccessoryInfo->Reset();
 
iAccessoryInfo->CopyL(aAccessoryInfo);
 
// Bring application to foreground
if (iAccessoryInfo->AccDeviceType() == KAccMonHeadset)
{
TApaTask task(CEikonEnv::Static()->WsSession());
task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
task.BringToForeground();
}
}
...
void CAccMonitorTest::DisconnectedL(CAccMonitorInfo* aAccessoryInfo)
{
// Reserve memory for the accessory information instance if necessary
if (!iAccessoryInfo)
iAccessoryInfo = CAccMonitorInfo::NewL();
// Otherwise just reset accessory information instance
else
iAccessoryInfo->Reset();
 
iAccessoryInfo->CopyL(aAccessoryInfo);
 
// Send application to background
if (iAccessoryInfo->AccDeviceType() == KAccMonHeadset)
{
TApaTask task(CEikonEnv::Static()->WsSession());
task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
task.SendToBackground();
}
}

Postconditions

Specific accessory connected/disconnected notifications have been handled.

This page was last modified on 8 February 2012, at 05:20.
52 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×