获取国家/地区的货币代码

Ego*_*gor 5 java android location locale currency

我在获取国家/地区的货币代码时遇到问题.我的任务是获取用户的位置,找出他现在所在的国家/地区并获取该国家/地区的货币代码.以下是从获取的位置获取国家/地区名称和国家/地区代码的代码:

Geocoder gc = new Geocoder(this);
List<Address> addresses = gc.getFromLocation(
                location.getLatitude(), location.getLongitude(), 5);

textView1.setText(addresses.get(0).getCountryName());
textView2.setText(addresses.get(0).getCountryCode());
Run Code Online (Sandbox Code Playgroud)

这完全没问题.现在我应该使用java.util.Currency类来获取一个Currency对象.我可以使用这个Currency.getInstance(Locale locale)方法.但是Locale类中没有构造函数只允许将国家/地区代码作为参数传递.意味着我无法Locale为国家创建对象.怎么解决这个问题?提前致谢.

Vla*_*lad 5

Currency.getInstance(new Locale("",code))如果国家/地区代码无效,您应该可以使用可能的例外情况.