Monday, September 21, 2009

Run BlackBerry Application without APN -Dynamically add APN from XML file

Most time we need to connect internet and use web services without setting apn.Some times user may use different sim cards and different service providers but application must work with them all without changing

In this dialog box we will display web page content of given url.Here getpage() method and getTag() methods are in my blog so simply you can  use them

String mcc = Integer.toHexString(RadioInfo.getMCC  (RadioInfo.getCurrentNetworkIndex()));
String mnc = Integer.toHexString(RadioInfo.getMNC(RadioInfo.getCurrentNetworkIndex())); Dialog.alert(getTag(ReadFile(),mcc+","+mnc));
Dialog.alert(getPage("http://www.google.com"+";deviceside=true;apn="+getTag(ReadFile(),mcc+","+mnc)));//Dialog will display web page content

//New URL is= ("http://www.google.com"+";deviceside=true;apn="+getTag(ReadFile(),mcc+","+mnc))

 

ReadFile Method

public String ReadFile()
{
//This retturns the String in FileName.txt
//File must locate in Src Folder
try {
Class classs = Class.forName("pkgName.className");//Replace package name and class name with your parameters
//Source Package neme and Class name
InputStream is = classs.getResourceAsStream("/test.txt");//test.txt add to your package folder
byte[] data = new byte[is.available()];
is.read(data, 0, is.available());
String c =new String(data);
return c;
}
catch (Exception ioe)
{
Dialog.alert("Error");
return null;
}
}

 

test.txt

This File provides apn according to the values of mcc and mnc

<310,12></310,12>
<310,4></<310,4> verizon
<310,38></310,38>     AT&T
<310,90></310,90>
<310,150></310,150>
<310,680></310,680>
<310,410></310,410>
<310,160>wap.voicestream.com</310,160>
<310,170>wap.voicestream.com</310,170>
<310,260>wap.voicestream.com</310,260>
<310,490>wap.voicestream.com</310,490>
<310,26>wap.voicestream.com</310,26>
<890,126>wap.voicestream.com</890,126>
<413,2>dialogbb</413,2>
<302,720>internet.com</302,720>
<22e2,0></22e2,0>

1 comment: