Below is a part of my code that sets the phone number automatically.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference connectionPref = findPreference(key);
if (connectionPref != null) {
connectionPref.setSummary(sharedPreferences.getString(key, ""));
}
//get phone number automatically
if (key.equals("pref_phone_number")) {
if (ContextCompat.checkSelfPermission(MainActivity.getContext(), android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
}
TelephonyManager tMgr = (TelephonyManager) MainActivity.getContext().getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
connectionPref.setSummary(mPhoneNumber);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, mPhoneNumber);
editor.commit();
}
}
Would it be possible to have the EditTextPreference
programmatically filled with mPhoneNumber
when it's clicked on and the edit window opens? I want to give the user the ability to edit their number, which right now they can not.