zoukankan      html  css  js  c++  java
  • android 模拟按钮点击

    引用:http://zhidao.baidu.com/question/127090389

    启动activity   可以使用InstrumentationTestCase
    发送手机事件
    Instrumentation.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
         Instrumentation.sendCharacterSync(KeyEvent.KEYCODE_DPAD_CENTER); 
    
    使用android的测试功能,写一个类继承InstrumentationTestCase
    然后在这个类里获得Instrumentation实例,通过它可以启动Activity,发送手机事件等 
    
    ------------------------------------------------------
    import android.app.Instrumentation;
    import android.content.ContentResolver;
    
    public class ActivityTest extends InstrumentationTestCase {  
    
        private Instrumentation mInst = null;
        private ContentResolver mContentResolver = null;     
        
            @Override
     protected void setUp() throws Exception {
        super.setUp();
        mInst = getInstrumentation();
        mContentResolver = mInst.getContext().getContentResolver();
       
    
     }
     
     public void testStartActivity() throws Exception {
          //launch activity
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String activityPackagePath = "com.android.";
            intent.setClassName(activityPackagePath, TargetActivity.getClass().getName());
            TargetActivity mActivity = (TargetActivity) getInstrumentation().startActivitySync(intent);
            mInst.waitForIdleSync();
            //send keyevent to press button
            mInst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
            mInst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_CENTER);
            mInst.waitForIdleSync();
     }
           
    }
  • 相关阅读:
    JS
    JS
    JS
    VUE
    element-ui 进入页面 message 自动触发的问题
    JS-数组中常用的方法
    CSS-transition简单过渡动画
    vue
    JS
    2021要买的书籍
  • 原文地址:https://www.cnblogs.com/sode/p/2615712.html
Copyright © 2011-2022 走看看