import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
class Dtmf {
private static final String CALL_MANAGER = "com.android.internal.telephony.CallManager";
private static final String SEND_DTMF = "sendDtmf";
private static final String GET_INSTANCE = "getInstance";
private Method mSendDtmfMethod;
private Object mCallManager;
public Dtmf() {
try {
Class<?> callManagerClass = Class.forName(CALL_MANAGER); // Obtain
// an
// instance
// of
// CallManager
Method getInstanceMethod = callManagerClass.getMethod(GET_INSTANCE);
mCallManager = getInstanceMethod.invoke(null);
// Get sendDtmf(char)
Class<?>[] sendDtmfParamTypes = new Class<?>[] { char.class };
mSendDtmfMethod = callManagerClass.getMethod(SEND_DTMF, sendDtmfParamTypes);
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
public boolean sendDtmf(char ch) {
boolean result = false;
if (mCallManager != null && mSendDtmfMethod != null) {
try {
Object res = mSendDtmfMethod.invoke(mCallManager, new Object[] { Character.valueOf(ch) });
if (res instanceof Boolean) {
result = ((Boolean) res).booleanValue();
}
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
return result;
}
}