0

When a call comes after checking certain condition if its satisfy i want to attend that call automatically, else it should decline. can any one help me how to attend or decline a call through my app. i tried to use the below code but i cannot able to import the package "com.android.internal.telephony.ITelephony"

private void getTeleService() {
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    try {
        // Java reflection to gain access to TelephonyManager's
        // ITelephony getter
        Log.v(TAG, "Get getTeleService...");
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG,
                "FATAL ERROR: could not connect to telephony subsystem");
        Log.e(TAG, "Exception object: " + e);
    }
  }


 telephonyService.answerRingingCall();
 telephonyService.endCall();
4

0 回答 0