What is the best way to get country code? As of now I know two ways one is to get by TelephonyManager and another by Locale which is the other best & unique way to find country code in android.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
It is better than
getSimCountryIso
becausegetSimCountryIso
depends on the operator to burn the country iso on the SIM and it also supports CDMA networks.There is an excellent article by Reto Meier: http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html
It describes different techniques to get location of an android device, including source code. Next, when you have location, it's easy to get country for it - use can use online web-service or offline database
Here is a complete example. Try to get country code from TelephonyManager (from SIM or CDMA devices), and if not available try to get it from local configuration.
Also another idea is to try an API request like in this answer, or to use fine location.
References here and here