1. 得到存取點ID(IAP ID)
在用如下代碼建立串連時:
RSocketServ socketServ;
RConnection connection;
TCommDbConnPref pref;
TRequestStatus rsConn, rsTimeout;
Timer Timer;
User::LeaveIfError(socketServ.Connect());
User::LeaveIfError(connect.Open(socketServ));
pref.SetDialogPreference(ECommDbDialogPrefPrompt);
pref.SetDirection(ECommDbConnectionDirectionOutoing);
pref.SetBearerSet(ECommDbBearerUnknown);
if(Timer.CreateLocal() == KErrNone)
{
Timer::After(rsTimeout, 30 * 1000 * 1000)
connection.Start(pref, rsConn);
User::WaitForRequest(rsConn, rsTimeout);
switch(rsConn.Int())
{
case KErrNone:
case KErrInUse;
case KErrAlreadyExists:
dafault:
}
if(rsConn == KRequestPending)
{
connection.Stop();
User::WaitForRequest(rsCconn);
}
if(rsTimeout == KRequestPending)
{
Timer::Calcel();
User::WaitForRequest(rsTimeout);
}
Timer::Close();
}
connection.Close();
socketServ.Close();
會有提示選擇存取點的對話方塊出現. 在選擇了存取點之後, 可以用:
TUint32 iap(0);
_LIT(KCommdbIapSetting, "IAP//Id");
User::LeaveIfError(connection.GetIntSetting(KCommdbIapSetting, iap));
得到存取點的ID, 這裡iap就是存取點的ID.
2, 獲得活躍的存取點
TUint32 iap = 0;
RSocketServ socketServ;
User::LeaveIfError(socketServ.Connect());
CleanupClosePushL(socketServ);
RConnection conn;
User::LeaveIfError(conn.Open(socketServ));
CleanupClosePushL(conn);
TUint count = 0;
User::LeaveIfError(conn.EnumerateConnections(count));
TConnectionInfoBuf connectionInfo;
TUint i;
for(; count > 0; count--)
{
User::LeaveIfError(conn.GetConnectionInfo(count,connectionInfo));
iap = connectionInfo().iIapId;
}
CleanupStack::PopAndDestroy(2, &socketServ);
3, 輪詢可用的存取點:
3.1
(from: http://www.ok371.cn/html/13/0/999/1.htm)
How do I get a list of Internet Access Point (IAP) names and the corresponding ID values?
Answer:
An Internet Access Point (IAP) is a table in Symbian's Communication database (CommDB) which provides an entry point for making a connection over a given bearer type e.g. GPRS, WCDMA, GSM Data Call etc. There can be several IAP records in the IAP table within CommDB each pointing to a different connection type.
Note : The example code below uses Symbian OS APIs directly. Some SDKs might include UI Platform specific APIs to achieve the same thing. You can use
the Symbian APIs to allow your solution to work over different platforms - though any future changes made to CommDB API/functionality will affect your
implementation.
How do I get a list of IAP's names?
The below code snippet below showshow to get the IAP names for GPRS (and also WCDMA).
TUint32 CCommsDBAccessor::GetGPRSIAPsFromIAPTableL(CDesCArrayFlat* aList)
{
TBuf<52> iapfromtable;
TInt err = KErrNone;
// Open IAP table using the GPRS as the bearer.
CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerGPRS,
ECommDbConnectionDirectionOutgoing);
// Point to the first entry
User::LeaveIfError(gprsTable->GotoFirstRecord());
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
aList->AppendL(iapfromtable);
while (err = gprsTable->GotoNextRecord(), err == KErrNone)
{
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
aList->AppendL(iapfromtable);
}
CleanupStack::PopAndDestroy(); // gprsTable
}
How do I get the IAP ID values?
You can extend the second example above to get the IAP value. Include the line below
to read the IAP value for each record.
TUint32 id=0;
gprsTable->ReadUintL(TPtrC(COMMDB_ID), id);
The IAP value can be used in the override settings when making a connection. See FAQ 1064 for more details.
3.2
CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDb);
//commDb->ShowHiddenRecords(); //如果調用了這個函數,而程式又沒有相應都許可權, 那麼在調用commDb->OpenTableLC(時會有異常拋出,該異常無法被抓住。
CCommsDbTableView* view = commDb->OpenTableLC(TPtrC(IAP));
for (TInt i = view->GotoFirstRecord(); i != KErrNotFound; i = view->GotoNextRecord())
{
TUint32 iapId;
TBuf<512> iapName;
view->ReadUintL(TPtrC(COMMDB_ID), iapId);
view->ReadTextL(TPtrC(COMMDB_NAME), iapName);
}
CleanupStack::PopAndDestroy(2, commDb); // view, commDb
iapTable->ReadUintL(TPtrC(COMMDB_ID), id);
iapTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
if (iapfromtable == findString)
return id;
while (err = iapTable->GotoNextRecord(), err == KErrNone)
{
iapTable->ReadUintL(TPtrC(COMMDB_ID), id);
iapTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
if (iapfromtable == findString)
return id;
}
return KErrNotFound;
}