Reliable method to get the country the user is in?

后端 未结 5 1005
情话喂你
情话喂你 2020-12-05 03:19

I usually get the country from the device\'s language. It works but now I have to recognize Brazil. And most of the devices only have portuguese (pt_PT), and no portuguese (

5条回答
  •  清歌不尽
    2020-12-05 03:31

    It's working on me.

    String countryISOCode;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        TelephonyManager teleMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        if (teleMgr != null){
            countryISOCode = teleMgr.getSimCountryIso();
        }
    

    ............................

提交回复
热议问题