獲取iapId

 

函數:

TInt GetIap(const TDesC8& aData)
{
 CCommsDatabase* CommDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
 CleanupStack::PushL(CommDb);
 TBuf<64> Name;
 TBuf<64> Name1;
 TBuf<64> Name2;
 TBuf<20> wap;
 wap.Copy(aData);
 wap.LowerCase();

 TBool result = EFalse;
 TUint32 id = 0;
 TInt iapId = 0;
 CCommsDbTableView* tableIAP = CommDb->OpenTableLC(TPtrC(OUTGOING_GPRS));

 if (tableIAP->GotoFirstRecord()==KErrNone)
 {
  do
  {
   tableIAP->ReadTextL(TPtrC(COMMDB_NAME),Name1);
   tableIAP->ReadTextL(TPtrC(GPRS_APN),Name);
   Name.LowerCase();
   Name1.LowerCase();
   if(Name.Find(wap) != KErrNotFound)
   {   
    result = ETrue;
    break;
   }
  }while(tableIAP->GotoNextRecord()==KErrNone);
 }
 CleanupStack::PopAndDestroy(tableIAP); //
 CleanupStack::PopAndDestroy(CommDb); //
 if(result)
 {
  CCommsDatabase* CommDb1 = CCommsDatabase::NewL(EDatabaseTypeIAP);
  CleanupStack::PushL(CommDb1);
  CCommsDbTableView* tableIAP1 = CommDb1->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerGPRS,ECommDbConnectionDirectionOutgoing);
  tableIAP1->GotoFirstRecord();
  do
  {
   tableIAP1->ReadTextL(TPtrC(COMMDB_NAME),Name2);
   Name2.LowerCase();
   if(Name2.Find(Name1) != KErrNotFound)
   {
    TUint32 intVal=0;
    tableIAP1->ReadUintL(TPtrC(COMMDB_ID), intVal);
    iapId = intVal;
    break;
   }
  }while(tableIAP1->GotoNextRecord()==KErrNone);
  CleanupStack::PopAndDestroy(tableIAP1); //
  CleanupStack::PopAndDestroy(CommDb1); //
 }
 return iapId;
}

 

使用:

TInt iapID = GetIap(_L8("cmwap"));

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章