4

I intend to write tests related to the Phone and Direct SIM write.

What are the alternatives in case the required APIs aren't exposed in TelephonyManager but exist as private APIs in PhoneBase.java, PhoneFactory.java or CommandInterface.java?

Specifically, my questions are:

  1. What is the "replacement" for: PhoneFactory.getDefaultPhone()?
  2. What is the alternative in order to access the CommandsInterface (e.g.: CommandsInterface mCmdIf = ((PhoneBase)mPhone).mCM)?

Thanks in advance,
Micha

4

1 回答 1

6

您可以使用java reflection.

这是我如何访问 com.android.internal.telephony.ITelephony类的方法来阻止来电...

private void endCall() throws Exception {
      TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

      Class<?> c = Class.forName(tm.getClass().getName());
      Method m = c.getDeclaredMethod("getITelephony");
      m.setAccessible(true);
      ITelephony telephonyService = (ITelephony) m.invoke(tm);

      telephonyService.silenceRinger();
      telephonyService.endCall();
      Toast.makeText(context, "Call Ended !", Toast.LENGTH_SHORT).show();
}
于 2011-08-26T06:49:48.837 回答