UiAutomator自动化测试脚本挂断电话

 
 
在构造函数里实例化context
	this.targetContext=InstrumentationRegistry.getTargetContext();
    public void hangUpCommand() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        TelephonyManager telephonyManager = (TelephonyManager)targetContext.getSystemService(Context.TELEPHONY_SERVICE);
        Class<TelephonyManager> c = TelephonyManager.class;
        Method mthEndCall = c.getDeclaredMethod("getITelephony",(Class[])null);
        mthEndCall.setAccessible(true);
        final Object obj = mthEndCall.invoke(telephonyManager,(Object[])null);
        Method mt = obj.getClass().getMethod("endCall");
        mt.setAccessible(true);
        mt.invoke(obj);
    }

猜你喜欢

转载自blog.csdn.net/xyd_113/article/details/76716106