1

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?

Beloo
  • 9,723
  • 7
  • 40
  • 71
W. van de Ven
  • 31
  • 1
  • 7
  • Check the answer at https://stackoverflow.com/questions/22163424/android-java-lang-securityexception-injecting-to-another-application-requires/33489854, worked for me – David Santiago Turiño Jan 22 '18 at 10:39

1 Answers1

2

I found a solution. Try using mediarecorder using this video: https://www.youtube.com/watch?v=69J2ycNCtpE

W. van de Ven
  • 31
  • 1
  • 7
  • External links may go stale (e.g., the YouTube video might not be available forever). It would be a lot better if you'd summarize the fix here, in addition to linking to the source. – Jeremy Figgins Oct 03 '18 at 16:52