I'm trying to simulate a click on the recording button, when starting the MediaStore.ACTION_VIDEO_CAPTURE
. My goal is to let the application immediately start recording when the intent is started. But when I run my code I get the following
error: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
. The INJECT_EVENTS permission is only allowed by system apps. This is my code:
Uri uri = Uri.fromFile(videoFile);
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 15);
videoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(videoIntent, videoRequest);
new Thread(new Runnable() {
@Override
public void run()
{
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_RECORD);
}
}).start();
Is there maybe another solution to start recording when the intent is started?