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);
}
source
share