1.fragmentAccessibilityFragment的對象。须要被調用的方法的類。

setAccessible(true)并非将方法的訪问权限改成了public。而是取消java的权限控制检查。所以即使是public方法。其accessible属相默认也是false  

     try {

            Class mClass = Class.forName(“com.sonymobile.chameleon.workflow.step.AccessibilityFragment”);
            Method method = mClass.getDeclaredMethod(“isAccessibilityEnabled”);
            method.setAccessible(true);
            if(!Boolean.parseBoolean((method.invoke((Object)fragment,null)+””))) {
                method = mClass.getDeclaredMethod(“enableAccessibility”);
                method.setAccessible(true);//私有方法

                method.invoke((Object)fragment,null);//調用方法,null:爲傳遞的参數

                //method.invoke((Object)getService(),new Object[]{getContext()});帶参方法

            }
        } catch (ClassNotFoundException e) {
            Log.d(TAG, “1”);
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            Log.d(TAG, “2”);
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            Log.d(TAG, “3”);
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            Log.d(TAG, “4”);
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            Log.d(TAG, “5”);
            e.printStackTrace();
        }

版权声明:本文为brucemengbm原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/brucemengbm/p/6970838.html