You Are Here:

Community: Wiki

This page was last modified on 30 September 2009, at 13:38.

Listening a specific accessory connected/disconnected notifications

From Forum Nokia Wiki

Reviewer Approved   


ID   Creation date  November 02, 2008
Platform  S60 5th Edition Tested on devices  
Category  Symbian C++ Subcategory  


Keywords (APIs, classes, methods, functions): Accessory Monitoring API, CAccMonitor, RConnectedAccessories, CAccMonitorInfo, KAccMonHeadset, KAccMonWired


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.

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.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia