国家/地区名称null正在获取使用TelephonyManager在安卓6.0中使用version.Below 6.0国家/地区名称正在获取并且我也授予了权限但它不是working.Could您请帮助me.Thank您
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();
}
}
发布于 2018-02-09 01:28:56
我在使用禁用了第一个SIM卡的双SIM卡设备/电话时遇到此问题。启用后,我得到了期望值。这是一种特殊情况,但可能会帮助处于类似情况的人。
https://stackoverflow.com/questions/44752072
复制相似问题