I'm trying to use the new APN api
The code looks like this
DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName deviceAdmin = new ComponentName(getApplicationContext(), DeviceAdmin.class);
ApnSetting apn = (new ApnSetting.Builder())
.setApnTypeBitmask(ApnSetting.TYPE_DEFAULT)
.setApnName("sonme.real.apn.url")
.setEntryName("Some Entry")
.setCarrierEnabled(true)
.build();
int re = dpm.addOverrideApn(deviceAdmin, apn);
dpm.setOverrideApnsEnabled(deviceAdmin, true);
But except the fact that the APN menu becomes unavailable (locked to admin - which is OK) the APN is not working
p.s
I checked with dpm.getOverrideApns(deviceAdmin);
and the added apn is present...
And I also tried setting the setProtocol
and setRoamingProtocol
Any Ideas?
Finally figured out what was missing
It appears that when adding apns using the API you must explicitly specify the
setProtocol
,setRoamingProtocol
and thesetOperatorNumeric
,its a must and its consists from Telephony.Carriers.MCC + Telephony.Carriers.MNC (in my case, I had to pad the MNC with a leading zero)p.s
MCC and MNC could be fetched from
TelephonyManager, getSimOperator()
(getSimOperator().substring(3) and getSimOperator().substring(0, 3)
)