mercredi 13 juillet 2016

Hangup call in java Android - Samsung and HTC

I'm using the code shown here and it's working on Nexus 5, it doesn't work on Samsung or HTC as getITelephony doesn't exist, anyone got this to work in Samsung and/or HTC?

public boolean killCall(Context context) {
    try {
        // Get the boring old TelephonyManager
        TelephonyManager telephonyManager =
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        // Get the getITelephony() method
        Class classTelephony = Class.forName(telephonyManager.getClass().getName());
        Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony");

        // Ignore that the method is supposed to be private
        methodGetITelephony.setAccessible(true);

        // Invoke getITelephony() to get the ITelephony interface
        Object telephonyInterface = methodGetITelephony.invoke(telephonyManager);

        // Get the endCall method from ITelephony
        Class telephonyInterfaceClass =  
                Class.forName(telephonyInterface.getClass().getName());
        Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall");

        // Invoke endCall()
        methodEndCall.invoke(telephonyInterface);

    } catch (Exception ex) { 

        //*****EXCEPTION thrown here********

        Log.d(TAG,"PhoneStateReceiver **" + ex.toString());
        return false;
    }
    return true;

Aucun commentaire:

Enregistrer un commentaire