Narendra
- Forum posts: 1
Jun 23, 2017, 7:03:05 AM via Website
Jun 23, 2017 7:03:05 AM via Website
Country name is getting null using TelephonyManager in android 6.0 version.Below 6.0 country name is getting and i also gave permissions but its not working.Could you please help me.
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();
}
}