关于双卡双待手机的基站变化监听
单卡手机只需调用TelephonyManager的listen就能够实现监听,代码如下:
TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
tel.listen(new TelLocationListener(), PhoneStateListener.LISTEN_CELL_LOCATION);
public class TelLocationListener extends PhoneStateListener{
@Override
public void onCellLocationChanged(CellLocation location){
super.onCellLocationChanged(location);
..............
}
}
现在对一款三星双卡双待手机的基站更新进行监听,通过类投射发现该设备的隐藏函数,如:
public android.telephony.CellLocation android.telephony.TelephonyManager.getCellLocationDs(int)
public java.lang.String android.telephony.TelephonyManager.getDeviceIdDs(int)
public void android.telephony.TelephonyManager.listenDs(int,android.telephony.PhoneStateListener,int)
调用前两个函数能够成功获取双卡各自信息
本以为调用listenDs能够实现双卡各自监听,却无法截获,代码如下:
{
...
listenBySlot("listenDs",0,new TelLocationListener(),PhoneStateListener.LISTEN_CELL_LOCATION);
listenBySlot("listenDs",1,new TelLocationListener(),PhoneStateListener.LISTEN_CELL_LOCATION);
...
}
private void listenBySlot(String predictedMethodName, int slotID,PhoneStateListener phoneStateListener,int state) {
TelephonyManager telephony = (TelephonyManager)
mContext.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[3];
parameter[0] = int.class;
parameter[1] = PhoneStateListener.class;
parameter[2] = int.class;
Method listen = telephonyClass.getMethod(predictedMethodName,parameter);
Object[] obParameter = new Object[3];
obParameter[0] = slotID;
obParameter[1] = phoneStateListener;
obParameter[2] = state;
listen.invoke(telephony, obParameter);
} catch (Exception e) {
Log.i("sbox","\n" + e.getMessage());
//throw new GeminiMethodNotFoundException(predictedMethodName);
}
}
有谁能指点一二,万分感谢!