Obtain access point information from commdb:
Ccommsdatabase * commsdb = ccommsdatabase: newl (edatabasetypeiap );
Ccommsdbtableview * Table = commsdb-> openiaptableviewmatchingbearersetlc (
Ecommdbbearergprs | ecommdbbearerwlan, // GPRS and wireless LAN
Ecommdbconnectiondirectionoutgoing); // It Doesn't Matter in the direction. You can also write unknown.
User: leaveiferror (Table-> gotofirstrecord (); // go to the first record.
Tint err = kerrnone;
Do
{
Tbuf <32> name;
Tuint32 ID;
Table-> readtextl (tptrc (commdb_name), name); // obtain the name of the current access point
Table-> readuintl (tptrc (commdb_id), ID); // obtain the iapid of the current access point
... // Do something
Err = table-> gotonextrecord (); // go to the next record
}
While (ERR = kerrnone );
AboveCodeDemonstrate how to traverse the Access Point list. The implementation method is direct. We can also use another encapsulated class capselect to implement it:
Ccommsdatabase * commdb = ccommsdatabase: newl (edatabasetypeiap );
Capselect * apselect = capselect: newlc (* commdb, keapisptypeall, eapbearertypeall, keapsortuidascending); // the ISP and bearer types and sorting rules are specified.
If (apselect-> movetofirst ())
{
Do
{
Tptrc A = apselect-> name (); // Access Point name
Tuint uid = apselect-> UID (); // Access Point iapid
// Put here your IAP stuff
}
While (apselect-> movenext (); // The next record
}
Dialog Box to allow users to select Access Points
You can use the rconnection class to determine the access point you want to use:
Rsocketserv isocketserv; // data member
Rconnection iconnection; // data member
User: leaveiferror (isocketserv. Connect ());
User: leaveiferror (iconnection. Open (isocketserv ));
Tcommdbconnpref connectpref;
Connectpref. setdialogpreference (ecommdbdialogprefprompt); // prompt the user
Connectpref. setbearerset (ecommdbbearerwlan | ecommdbbearergprs );
User: leaveiferror (iconnection. Start (connectpref ));//Synchronous Functions,A dialog box is displayed, waiting for the access point to be selected to establish a connection.
Here we select the Access Point and establish a connection to bind it. If we do not connect immediately after selecting the access point, how can we achieve this? Look down.
Show default access point settings &Connect without user confirmation
The default access point setting is to bring up the display screen of a specific access point in settings-connection-Access Point in the real machine. You can select different access points based on the actual situation. After obtaining the iapid of the access point you want to use, you can directly establish a connection as needed without confirmation:
Usage class:Capsettingshandler
// Show IAP selection dialog to list Access Points
Cactiveapdb * ADB = cactiveapdb: newl ();
Cleanupstack: pushl (ADB );
Capsettingshandler * settings = capsettingshandler: newlc (
* ADB,
Etrue,
Eapsettingssellistispopup,
Eapsettingsselmenuselectnormal,
Keapisptypeall,
Bearerfilter,
Keapsortnameascending,
0,
Evpnfilterboth,
Etrue );
Tint iapret = settings-> runsettingsl (0, iselectediap); // Save the selected access point to iselectediap
Cleanupstack: popanddestroy (settings );
Cleanupstack: popanddestroy (ADB );
If (iapret! = Kapuieventselected)
{
// Exit no selection
User: Leave (kerrnotready );
}
Else
{
// IAP selected, which is connected Based on the selected Access Point
// Open socket server and start the connection
User: leaveiferror (isocketserv. Connect ());
User: leaveiferror (iconnection. Open (isocketserv ));
// Now we have the iap id. Use it to connect for the connection
Tcommdbconnpref connectpref;
// Setup preferences
Connectpref. setdialogpreference (ecommdbdialogprefprompt );
// Sets the commdb ID of the IAP to use for this connection
Connectpref. setiapid (iselectediap );
// Start connection
User: leaveiferror (iconnection. Start (connectpref ));
...
}
The above code can be divided into two parts to achieve the separation of Access Point Selection and connection establishment. The code for establishing a connection is as follows:
// IAP selected, which is connected Based on the selected Access Point
// Open socket server and start the connection
User: leaveiferror (isocketserv. Connect ());
User: leaveiferror (iconnection. Open (isocketserv ));
// Now we have the iap id. Use it to connect for the connection
Tcommdbconnpref connectpref;
// Setup preferences
Connectpref. setdialogpreference (ecommdbdialogprefprompt );
// Sets the commdb ID of the IAP to use for this connection
Connectpref. setiapid (iselectediap );
// Start connection
User: leaveiferror (iconnection. Start (connectpref ));
Shielding system access points in MTM Mode
- Timiapchoice apchoice;
- Apchoice. IIAP = 0; // store IAP ID
- Apchoice. idialogpref = ecommdbdialogprefdonotprompt; // prompt Dialog
- Cimiappreferences * appref = cimiappreferences: newlc ();
- Appref-> addiapl (apchoice );
- Mailaccount-> savepopiapsettingsl (popaccount, * appref );
- Cleanupstack: popanddestroy (appref );