原文:http://topic.csdn.net/u/20091226/00/09e2979b-7c8c-4991-856d-586a278875c0.html
1. 在src下建立一個包:com.android.internal.telephony(和ITelephony.aidl 中 package 聲明的包名一樣);
2. 然後從系統源碼中把ITelephony.aidl檔案拷貝到 com.android.internal.telephony包下。(也可以先建立一個ITelephony.aidl, 然後再把內容拷貝進去(ITelephony.aidl檔案內容可以在http://www.netmite.com/android/mydroid/1.5/frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl 找到,這個方法適合沒有SDK源碼檔案的開發人員));
3. 在src下建立一個包:android.telephony, 然後建立一個NeighboringCellInfo.aidl,其內容為:
package android.telephony;
parcelable NeighboringCellInfo;
4.從私人方法中擷取ITelephony: 代碼如下。
tManager = (TelephonyManager)
this.getSystemService(Context.TELEPHONY_SERVICE);
//初始化iTelephony
Class <TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try {
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[])null);
getITelephonyMethod.setAccessible(true);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
iTelephony = (ITelephony) getITelephonyMethod.invoke(tManager, (Object[])null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}