private int getCallState()
{
int nState = 0;
Class<TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try
{
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null);
getITelephonyMethod.setAccessible(true);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Object iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null);
Method getCallState = iTelephony.getClass().getDeclaredMethod("getCallState");
nState = ((Integer) getCallState.invoke(iTelephony)).intValue();
}
catch (Exception e)
{
e.printStackTrace();
}
return nState;
}
Android 通过Java反射获取通话状态
最新推荐文章于 2024-05-09 12:19:51 发布