首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TelephonyManager.getNetworkCountryIso()在Android6.0中获取null

TelephonyManager.getNetworkCountryIso()在Android6.0中获取null
EN

Stack Overflow用户
提问于 2017-06-26 09:28:22
回答 1查看 856关注 0票数 1

国家/地区名称null正在获取使用TelephonyManager在安卓6.0中使用version.Below 6.0国家/地区名称正在获取并且我也授予了权限但它不是working.Could您请帮助me.Thank您

代码语言:javascript
运行
复制
private static final String[] PERMISSIONS = {
        Manifest.permission.READ_PHONE_STATE,
        Manifest.permission.ACCESS_COARSE_LOCATION
};
private TelephonyManager mTelephonyManager;
private EditText et_ind,et_us;
private Button bt_money_convert;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);       
    checkPermissions();
}
private void checkPermissions() {
    // Checks the Android version of the device.
    //if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) ||(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)) {
    if (Build.VERSION.SDK_INT >= 23){
        TelephonyManager mTelephonyManager= (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String getCountryName1 =mTelephonyManager.getNetworkCountryIso();
        Toast.makeText(MainActivity.this,"Location--->"+getCountryName1,Toast.LENGTH_LONG).show();

    } else {
        TelephonyManager mTelephonyManager= (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String getCountryName =mTelephonyManager.getNetworkCountryIso();
        Toast.makeText(MainActivity.this,"Location--->"+getCountryName,Toast.LENGTH_LONG).show();

    }
} 
EN

回答 1

Stack Overflow用户

发布于 2018-02-09 01:28:56

我在使用禁用了第一个SIM卡的双SIM卡设备/电话时遇到此问题。启用后,我得到了期望值。这是一种特殊情况,但可能会帮助处于类似情况的人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44752072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档