android2.3.5 CDMA/EVDO撥號APN解決方案

NO IMAGE

google提供的android2.3裡面,只能在GSM/WCDMA情況下才能從“設定”->“無線和網路”->“行動網路”->“接入點名稱”中選擇不同的apn帳號進行撥號連線,而CDMA/EVDO則沒有這個功能。最近看了一下程式碼,簡單實現了這個功能。

1、預設的CDMA/EVDO裡面連apn列表都不顯示,要先把這個挖出來。
修改packages/apps/Phone/res/xml/cdma_options.xml
新增如下內容
複製程式碼 程式碼如下:
<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>

還有development/data/etc/apns-conf.xml的version值改為原來的加1,原因程式碼裡面找。
2、修改frameworks/base/telephony/java/com/android/internal/telephony/cdma/cdmadataconnectiontracker.java的setupData函式
複製程式碼 程式碼如下:
private boolean setupData(String reason) {
CdmaDataConnection conn = findFreeDataConnection();
if (conn == null) {
if (DBG) log(“setupData: No free CdmaDataConnection 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, null, null, 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.notifyDataConnection(reason);
return true;
}

3、修改frameworks/base/telephony/java/com/android/internal/telephony/cdma/cdmadataconnection.java的onConnect函式:
複製程式碼 程式碼如下:
phone.mCM.setupDataCall(
Integer.toString(RILConstants.SETUP_DATA_TECH_CDMA),
Integer.toString(dataProfile),
//null, null, null,  //原來傳進撥號的引數都是空的!!!
cp.apn.apn, cp.apn.user, cp.apn.password,
Integer.toString(RILConstants.SETUP_DATA_AUTH_PAP_CHAP),
RILConstants.SETUP_DATA_PROTOCOL_IP, msg);

4、修改frameworks/base/telephony/java/com/android/internal/telephony/gsm/ApnSetting.java中對ApnSetting的定義,將其成員型別全部設為public

您可能感興趣的文章:

Android學習筆記(二)之電話撥號器Android電話撥號器實現方法Android程式設計實現讀取手機聯絡人、撥號、傳送簡訊及長按選單操作方法例項小結Android獲取手機通訊錄、sim卡聯絡人及呼叫撥號介面方法Android 2.3 撥號上網流程從原始碼角度進行分析Android撥號盤 支援T9搜尋和號碼搜尋等撥號盤案例Android開發之電話撥號器例項詳解