vendredi 28 octobre 2016

How to access internal telephony functionality of android 6.0 using java reflection?

I am trying to access some internal telephony methods.

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    try {
        Class telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
        Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
        getITelephonyMethod.setAccessible(true);


        Class ITelephonyClass = Class.forName(getITelephonyMethod.invoke(telephonyManager).getClass().getName());
        Method[] methods = ITelephonyClass.getDeclaredMethods();
        for (Method method : methods) {
            Log.i("Method", "Method name is: "+method.getName());
        }
        //ITelephonyClass.getMethod("isVolteAvailable",void.class).invoke(null,"");
        Method getInstanceMethod = ITelephonyClass.getDeclaredMethod("isVolteAvailable");
        getInstanceMethod.setAccessible(true);
        Object res = getInstanceMethod.invoke(null);
        boolean result = ((Boolean) res).booleanValue();

    }catch (Exception e){
        //newtext.setText(e.getMessage());
        Log.i("Exception", "Exception: "+e.getMessage());
        e.printStackTrace();
    }

Above code snippet is from Activity class. And permissions are given bellow

<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

But code is not giving the expected output.





Aucun commentaire:

Enregistrer un commentaire