swapnil gandhi
swapnil gandhi

Reputation: 816

Android: How to press two physical buttons at same time programatically

I am trying to press two physical button at same time with code, but I am able to deal with only 1 button. Here is the code:

 btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            new Thread(new Runnable() {
                @Override
                public void run() {

                    Instrumentation inst = new Instrumentation();

                    inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);//this is 1 button 



                }
            }).start();
        }
    });

How can I write code to press 2 buttons at same time?

Upvotes: 0

Views: 102

Answers (1)

Minas Mina
Minas Mina

Reputation: 2107

So, from the comments it seems you actually want to take a screenshot. Please state exactly your problem next time, don't make people guess.

As for your question, it actually seems to be possible using the MediaProjectionManager and a service. See this example project on github.

This only works on Android 5.0+.

Upvotes: 1

Related Questions