Andorid自身数据库中有很多默认的apn配置,如果要配置新的默认配置:
1、找到该文件:android-source/device/fsl/imx6/etc/apns-conf.xml
2、添加如下的格式的apn:
<apn carrier="Thailand TRUE 3GNET"
mcc="520"
mnc="04"
apn="internet"
user="true"
server=""
password="true"
mmsc=""
/>
3、因为RIL层在初始化拨号的时候会从sim卡中读取apn,然后把读出的apn和预先数据库中的apn对比,如果匹配就按照数据库的信息去拨号。
4、获取sim卡apn代码片段如下:
/**
* Based on the sim operator numeric, create a list for all possible
* Data Connections and setup the preferredApn.
*/
private void createAllApnList() {
mAllApns = new ArrayList<ApnSetting>();
String operator = mPhone.mIccRecords.getOperatorNumeric();
if (operator != null) {
String selection = "numeric = '" + operator + "'";
// query only enabled apn.
// carrier_enabled : 1 means enabled apn, 0 disabled apn.
selection += " and carrier_enabled = 1";
if (DBG) log("createAllApnList: selection=" + selection);
Cursor cursor = mPhone.getContext().getContentResolver().query(
Telephony.Carriers.CONTENT_URI, null, selection, null, null);
if (cursor != null) {
if (cursor.getCount() > 0) {
mAllApns = createApnList(cursor);
}
cursor.close();
}
}
if (mAllApns.isEmpty()) {
if (DBG) log("createAllApnList: No APN found for carrier: " + operator);
mPreferredApn = null;
// TODO: What is the right behaviour?
//notifyNoData(GsmDataConnection.FailCause.MISSING_UNKNOWN_APN);
} else {
mPreferredApn = getPreferredApn();
if (mPreferredApn != null && !mPreferredApn.numeric.equals(operator)) {
mPreferredApn = null;
setPreferredApn(-1);
}
if (DBG) log("createAllApnList: mPreferredApn=" + mPreferredApn);
}
if (DBG) log("createAllApnList: X mAllApns=" + mAllApns);
}