send Key to Context - Android android.app

Android examples for android.app:Instrumentation

Description

send Key to Context

Demo Code


//package com.java2s;

import android.app.Instrumentation;
import android.content.Context;

import android.os.AsyncTask;

public class Main {

    public static final void sendKey(final Context context,
            Integer... keyCodes) {
        new AsyncTask<Integer, Void, Void>() {
            @Override//from w  w w .  j a v a 2s.c  o  m
            protected Void doInBackground(Integer... keyCodes1) {
                Instrumentation cInstrumentation = new Instrumentation();

                for (Integer keyCode : keyCodes1) {
                    cInstrumentation.sendKeyDownUpSync(keyCode);
                }
                return null;
            }

            protected void onPostExecute(Void result) {

            };

        }.execute(keyCodes);
    }
}

Related Tutorials