How to activate snap group account on Symbian 9.x upwards platform

来源:互联网 发布:mac wifi未安装硬件 编辑:程序博客网 时间:2024/06/02 01:24
SNAP accounts use multiple access points which make it easy to start an internet connection and are a new feature found in UIQ 3 devices.

With the UIQ 2 platform, users would have to manually make these connections from the settings menu every time they changed their environment. With the UIQ 3 platform, anytime ActiveSync attempts to connect to the internet, the phone will automatically select the best network connection to be used without any user intervention.

Here is an example for activating a single Internet group on UIQ3.

// ------- gets the default snap account id
void GetDefaultIAPL(TUint32 &defaultSnapID) {
 CMDBSession *pDbSession = NULL;
 CMDBRecordSet<CCDGlobalSettingsRecord> *pGlobalSettingsRecSet = NULL;
 
 defaultSnapID = 0;
 
 // start the session
 pDbSession = CMDBSession::NewLC(CMDBSession::LatestVersion());

 // load the global settings
 pGlobalSettingsRecSet = new (ELeave) CMDBRecordSet<CCDGlobalSettingsRecord>(KCDTIdGlobalSettingsRecord);
 CleanupStack::PushL(pGlobalSettingsRecSet);
 pGlobalSettingsRecSet->LoadL(*pDbSession);
 
 // get the default SNAP ID
 if (pGlobalSettingsRecSet->iRecords.Count())
  defaultSnapID = static_cast<TUint32>((*pGlobalSettingsRecSet)[0]->iDefaultSnap);
 
 CleanupStack::PopAndDestroy(pGlobalSettingsRecSet); // pGlobalSettingsRecSet
 CleanupStack::PopAndDestroy(pDbSession); // pDbSession
}
//-------

//------- connnects to the internet
{
 TCommSnapPref iSNAPPrefs;
 RConnection iConnection;
 RSocketServ iSocketServer;
 TUint32 currIAPID = 0;

 iSocketServer.Connect();
 iConnection.Open(iSocketServer);

 GetDefaultIAPL(currIAPID); // please see function above for this
 iSNAPPrefs.SetSnap(currIAPID);

 iConnection.Start(iSNAPPrefs, iStatus);
 SetActive();
}
//-------

Another sample for getting list of Internet group names

//------- gets a list of snap accounts
class CSnapAccountInfo : public CBase
{
public:
 CSnapAccountInfo() : mpName(NULL), mId(0), mIsDefault(EFalse) { }
 virtual ~CSnapAccountInfo() { delete mpName; }
 
 HBufC* mpName;
 TUint32 mId;
 TBool mIsDefault;
};

void GetListOfAccessPointsL(CArrayPtrFlat<CSnapAccountInfo> **ppListSnapAccounts) {
 TUint32 defaultID = 0;
 CSnapAccountInfo *pCurrSnapAccountsInfo = NULL;
 CArrayPtrFlat<CSnapAccountInfo> *pLocalListSnapAccounts = NULL;
 
 CMDBSession *pDbSession = NULL;
 CMDBRecordSet<CCDGlobalSettingsRecord> *pGlobalSettingsRecSet = NULL;
 CMDBRecordSet<CCDAccessPointRecord> *pSnapRecordSet = NULL;
 CCDAccessPointRecord *pCurrSNAPRec  = NULL;
 
 // start the session
 pDbSession = CMDBSession::NewLC(CMDBSession::LatestVersion());

 // load the global settings
 pGlobalSettingsRecSet = new (ELeave) CMDBRecordSet<CCDGlobalSettingsRecord>(KCDTIdGlobalSettingsRecord);
 CleanupStack::PushL(pGlobalSettingsRecSet);
 pGlobalSettingsRecSet->LoadL(*pDbSession);

 // load the SNAp record list
 pSnapRecordSet = new (ELeave) CMDBRecordSet<CCDAccessPointRecord>(KCDTIdAccessPointRecord);
 CleanupStack::PushL(pSnapRecordSet);
 pSnapRecordSet->LoadL(*pDbSession);
 
 // get the default SNAP ID
 if (pGlobalSettingsRecSet->iRecords.Count())
  defaultID = static_cast<TUint32>((*pGlobalSettingsRecSet)[0]->iDefaultSnap);
 
 // create the array to hold the access point info
 *ppListSnapAccounts = NULL;
 pLocalListSnapAccounts = new (ELeave) CArrayPtrFlat<CSnapAccountInfo>(4);
 CleanupStack::PushL(pLocalListSnapAccounts);
 
 // parse the SNAP record list to extract the display info
 for (TInt i = 0; i < pSnapRecordSet->iRecords.Count(); ++i)
 {
  pCurrSNAPRec = (*pSnapRecordSet)[i];
  pCurrSnapAccountsInfo = new (ELeave) CSnapAccountInfo;
  CleanupStack::PushL(pCurrSnapAccountsInfo);
 
  TPtrC recNamePtr(pCurrSNAPRec->iRecordName);
  pCurrSnapAccountsInfo->mpName = recNamePtr.AllocL();
  pCurrSnapAccountsInfo->mId = pCurrSNAPRec->RecordId();
 
  if (pCurrSnapAccountsInfo->mId == defaultID)
   pCurrSnapAccountsInfo->mIsDefault = ETrue;
  
  pLocalListSnapAccounts->AppendL(pCurrSnapAccountsInfo);
  CleanupStack::Pop(pCurrSnapAccountsInfo);
 }
 
 // now pass back the list
 *ppListSnapAccounts = pLocalListSnapAccounts;
 CleanupStack::Pop(pLocalListSnapAccounts);
 
 CleanupStack::PopAndDestroy(pSnapRecordSet); // pSnapRecordSet
 CleanupStack::PopAndDestroy(pGlobalSettingsRecSet); // pGlobalSettingsRecSet
 CleanupStack::PopAndDestroy(pDbSession); // pDbSession }
//-------