In android2.3 provided by google, you can select a different apn account from "Settings"> "wireless and network"> "mobile network"> "Access Point name" only in the case of GSM/WCDMA for dial-up connection., but CDMA/EVDO does not have this function. I recently read the code to implement this function.
1. DefaultIn CDMA/EVDO, the list of apn is not displayed. You need to dig this out first.
Modify packages/apps/Phone/res/xml/CDMA _options.xml
Add the following content:Copy codeThe Code is as follows: <PreferenceScreen
Android: key = "button_apn_key"
Android: title = "@ string/apn_settings"
Android: persistent = "false">
<Intent android: action = "android. intent. action. MAIN"
Android: targetPackage = "com. android. settings"
Android: targetClass = "com. android. settings. ApnSettings"/>
</PreferenceScreen>
There is also the development/data/etc/apns-conf.xml version value to the original plus 1, The Reason code to find.
2. ModifyFrameworks/base/telephony/java/com/android/internal/telephony/cdma dataconnectiontracker. java setupData FunctionCopy codeThe Code is as follows: private boolean setupData (String reason ){
CDMA dataconnection conn = findFreeDataConnection ();
If (conn = null ){
If (DBG) log ("setupData: No free CDMA dataconnection found! ");
Return false;
}
MActiveDataConnection = conn;
String [] types;
If (mRequestedApnType. equals (Phone. APN_TYPE_DUN )){
Types = new String [1];
Types [0] = Phone. APN_TYPE_DUN;
} Else {
Types = mDefaultApnTypes;
}
// MActiveApn = new ApnSetting (0 ,"","","","","","","","","","",
// 0, types, "IP", "IP ");
Uri PREFERRED_APN_URI = Uri. parse ("content: // telephony/carriers/preferapn ");
ContentResolver cResolver = phone. getContext (). getContentResolver ();
Cursor cr = cResolver. query (PREFERRED_APN_URI, null );
Cr. moveToFirst ();
String user = cr. getString (cr. getColumnIndex ("user "));
String pass = cr. getString (cr. getColumnIndex ("password "));
String apn = cr. getString (cr. getColumnIndex ("apn "));
Log. e (LOG_TAG, "get apn: apn =" + apn + ", user =" + user + ", password =" + pass );
MActiveApn = new ApnSetting (0, "", "", apn, "", user, pass,
, Types, "IP", "IP ");
Message msg = obtainMessage ();
Msg. what = EVENT_DATA_SETUP_COMPLETE;
Msg. obj = reason;
Conn. connect (msg, mActiveApn );
SetState (State. INITING );
Phone. policydataconnection (reason );
Return true;
}
3. ModifyFrameworks/base/telephony/java/com/android/internal/telephony/cdma dataconnection. java onConnect function:Copy codeThe Code is as follows: phone. mCM. setupDataCall (
Integer. toString (RILConstants. SETUP_DATA_TECH_CDMA ),
Integer. toString (dataProfile ),
// Null, // The original parameters for incoming dialing are empty !!!
Cp. apn. apn, cp. apn. user, cp. apn. password,
Integer. toString (RILConstants. SETUP_DATA_AUTH_PAP_CHAP ),
RILConstants. SETUP_DATA_PROTOCOL_IP, msg );
4. ModifyFrameworks/base/telephony/java/com/android/internal/telephony/gsm/ApnSetting. java defines ApnSetting and sets all its member types to public.