Which Android sdk class can I use for change settings like APN, E911 or CMAS

I would like to know if anyone can point to a good source explaining how you can change the settings related to the phone, such as APN, E911 CMAS, using the Android SDK. I have noticed the Telephony Manager class as CarrierConfigManager, but I'm not sure what will give read / write access, or which is better, or if there are any better ways to do this.

+4
source share
1 answer

You can change the APN using the content provider provided by Telephony.Carriers .

Below is the code I used to create the new APN.

public void saveApn(Apn newApn) {
    String name = checkNotSet(newApn.getName());
    String apn = checkNotSet(newApn.getApn());
    String mcc = checkNotSet(newApn.getMcc());
    String mnc = checkNotSet(newApn.getMnc());

    ContentValues values = new ContentValues();

    values.put(Telephony.Carriers.NAME, name);
    values.put(Telephony.Carriers.APN, apn);

    values.put(Telephony.Carriers.MCC, mcc);
    values.put(Telephony.Carriers.MNC, mnc);
    values.put(Telephony.Carriers.NUMERIC, mcc + mnc);


    mContext.getContentResolver().insert(Telephony.Carriers.CONTENT_URI, values)
}

And set as preferred APN

private void setAsPreferedApn(int apnId) {
    ContentValues values = new ContentValues();
    values.put("apn_id", String.valueOf(apnId));
    getContentResolver().update(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "preferapn"), values, null, null);
}
+3
source

Source: https://habr.com/ru/post/1693886/


All Articles