Press "Enter" key via Instrumentation. - Android android.app

Android examples for android.app:Instrumentation

Description

Press "Enter" key via Instrumentation.

Demo Code

// Copyright 2012 The Chromium Authors. All rights reserved.
//package com.java2s;
import android.app.Instrumentation;
import android.view.KeyEvent;

public class Main {
    /**//from w w w. j av  a2  s  . com
     * Press "Enter".
     */
    public static void pressEnter(Instrumentation instrumentation) {
        instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
                KeyEvent.KEYCODE_ENTER));
        instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
                KeyEvent.KEYCODE_ENTER));
        instrumentation.waitForIdleSync();
    }
}

Related Tutorials