Network selection programetically
Please Login to Remove!
Hi all,
I am also trying to get the APN info through my application code.
I want to get the list of APN's present in the device and their corresponding username and password.
Hardcoding the APN info while making http connection is not a good idea as the carrier may change the
information at some point of time.
Please suggest me regarding this:
I have followed two ways but this does not seem to be good
1.
String url = connectionStr;
String network = RadioInfo.getCurrentNetworkName();
if(network != null){
network = network.toLowerCase();
if(network.startsWith("airtel")){
url = url + ";deviceside=true;apn=airtelgprs.com;";
return url;
}else {
return url ;
}
-----------------------------
2.
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
String uid = null;
for(int i=0; i < records.length; i++)
{
//Search through all service records to find the
//valid non-Wi-Fi and non-MMS
//WAP 2.0 Gateway Service Record.
if(records[i].isValid() && !records[i].isDisabled())
{
if(records[i].getUid() != null && records[i].getUid().length() != 0)
{
if((records[i].getUid.toLowerCase().indexOf("wptcp") != -1) &&
(records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
(records[i].getUid().toLowerCase().indexOf("mms") == -1))
{
uid = records[i].getUid();
return;
}
}
}
}
if (uid != null)
{
//Using WAP2
//";ConnectionUID=" + uid;
return;
} else {
//Using APN (Direct TCP)
//";deviceside=true";
return;
}.
I dont really know whether we can get the APN username and password using the second code snipet.
Please suggest me regarding this.
thanks
|