Menu

Remote injection

The remote injection feature allows MDM providers to inject mouse and keyboard events from an MDM console to a device. This feature enables enterprise IT admins to set up or troubleshoot a device remotely, by injecting key, touch, or trackball events on an enterprise device.

The class RemoteInjection in the package com.samsung.android.knox.remotecontrol enables you to:

The following sample code shows how to use remote injection to tap keys like Home and Back, launch apps like Settings and Camera, and simulate keyboard text entry.

Get a remote injection instance

First get an instance of a device manager, then get an instance of a remote injection.

EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
RemoteInjection remoteInjection = edm.getRemoteInjection();

Inject key events

The following examples show how to launch the Settings app, tap the Back key, tap the Home key, launch the Camera app, and tap Back again.

remoteInjection.injectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SETTINGS), true);
remoteInjection.injectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK), true);
remoteInjection.injectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HOME), true);
remoteInjection.injectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CAMERA), true));
remoteInjection.injectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK), true));

Inject text entry

The key events are defined by the Android class KeyEvent. In this example, simulate the keyboard entry of the character 0:

int keycode = KeyEvent.KEYCODE_0;
remoteInjection.injectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keycode), true);

Inject pointer event

This example simulates a tap at screen pixel location 100 x 200 on the device screen:

int x = 100, y = 200,flags = 0;
remoteInjection.injectPointerEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x, y, flags), true);