Friday, July 16, 2010

Get default currency value from BB device

If you are looking to get the default currency from your code you have to go for
RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex()).

Mcc means the Mobile country code.

public String setCurrency()
{
String currency="$";//default currency symbol
String array[]={"€","$","Rs","BZ$","£","R$",
"₪","R","¥","₩","руб","CHF"};
//all Character is in UTF-8. and copy from the http://www.xe.com/symbols.php
String euro[]={"225","204","278","270","222",
"208","206","202","272","293","214"};//MCC for the country which used euro sign
String pound[]={"417","248","602","348","274","266","415"
,"360"}; //MCC for the country which used pound sign
int li_Radio = RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex());
String x = Integer.toHexString(li_Radio);//MCC for country.
boolean flag=false;
for(int i=0;i<euro.length;i++)
{if(x.equals(euro[i])){flag=true;
currency=array[0];//set Euro currency symbol
break;
}}
if(flag==false){
for(int i=0;i<pound.length;i++){
if(x.equals(pound[i])){
flag=true;
currency=array[4];//set Euro currency symbol
break;
}}}
if(flag==false){
if(x.equals("724")){
currency=array[3];//set Brazil currency symbol.
}else if(x.equals("425")){
currency=array[6];//set Israel currency symbol.
}else if(x.equals("655")){
currency=array[7];//set SountAfria currency symbol.
}else if(x.equals("467")||x.equals("450")){
currency=array[9];//set Koria currency symbol.
}else if(x.equals("441")||x.equals("460")){
currency=array[8];//set China or Japan currency symbol.
}else if(x.equals("413") || x.equals("404") || x.equals("405") || x.equals("410") || x.equals("429")){
currency=array[2];//set India or Nepal or Pakistan or Srilanka currency symbol.
}else if(x.equals("250")){
currency=array[10];//set Russian currency symbol.
}else if(x.equals("228")){
currency=array[11];//set Switzerland currency symbol.
}}
return currency;
}

First go to project property and click Text File Encoding checkbox to other and set encoding to UTF-8.

This code work on real device not in simulator.Set currency according to MCC and check current mobile network.


#2)Another method if you are not having a network carrier and you are using wi-fi

This code is set to currency symbols according to phone language setting.

public static String setCurrency()
{
String currency="$";//set $ as a default currency.
String array[]={"$","£","€"};
String x = Locale.getDefaultForSystem().toString();//MCC
if(x.equalsIgnoreCase("fr")){
currency=array[2];//set € symbol.
}else if(x.equalsIgnoreCase("es")){
currency=array[2]; //set € symbol.
}else if(x.equalsIgnoreCase("en_us")){
currency=array[0];//set $ symbol.
}else if(x.equalsIgnoreCase("en_gb")){
currency=array[1];//set £ symbol.}
return currency;
}

By the above method we can get through the languages which are supported by the device.

reference:

http://supportforums.blackberry.com/t5/Java-Development/how-to-get-default-currency-value-from-BB-device/td-p/510638





No comments:

Post a Comment