Android: Runtime.getRuntime().exec(String)命令太慢?还是我做错了什么?

huangapple go评论81阅读模式
英文:

Android: Runtime.getRuntime().exec(String) command is too slow? or I am doing something wrong?

问题

I am trying to create an app which I use it for remote control an android device(TV). Actually I did it however when I click a button on the controller device(mobile), it takes apprx. 1 sec to do the work in the device(TV) that I want to control.

当我在控制设备(手机)上点击按钮时,实际上我已经实现了远程控制安卓设备(电视),但是它需要大约1秒的时间来完成我想要控制的设备(电视)上的工作。

When I checked all logs in the code and I see that method spends that much time...

当我检查了代码中的所有日志后,我发现这个方法花费了那么多时间...

String commandStr;
commandStr = String.format("%s"," input keyevent "+keyCode);

try {
process = runTimeExec(commandStr);
runTimeExec(commandStr);
} catch (IOException e) {
}

And the runTimeExec defined as;

并且runTimeExec被定义为:

public static Process runTimeExec(String commandStr) throws IOException {
Runtime.getRuntime().exec(commandString);
}

I just wanna learn if there is any other solution to run command immediately on the TV device itself? Or how can I make faster this code here?

我只是想知道是否有其他方法可以立即在电视设备上运行命令?或者如何使这段代码更快?

英文:

I am trying to create an app which I use it for remote control an android device(TV). Actually I did it however when I click a button on the controller device(mobile), it takes apprx. 1 sec to do the work in the device(TV) that I want to control.

When I checked all logs in the code and I see that method spends that much time...

    String commandStr;
    commandStr = String.format("%s"," input keyevent "+keyCode);

    try {
        process = runTimeExec(commandStr);
        runTimeExec(commandStr);
    } catch (IOException e) {
    }

And the runTimeExec defined as;

    public static Process runTimeExec(String commandStr) throws IOException {  
           Runtime.getRuntime().exec(commandString);

    }

I just wanna learn if there is any other solution to run command immediately on the TV device itself? Or how can I make faster this code here?

答案1

得分: 0

我已经使用了getevent/sendevent代码来实现这个目的。它非常快速,可以立即在电视设备上运行。只需尝试一下。您可以在https://source.android.com找到详细的文档。

英文:

I've used the getevent/sendevent code for this purpose. Its very fast and works immediately on the TV device. Just try it. You can find detailed documentations in https://source.android.com

答案2

得分: 0

Oğuz Gençer 的意思是这样的:

Instrumentation backExecutor = new Instrumentation();
backExecutor.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
英文:

Oğuz Gençer mean this :

Instrumentation backExecutor = new Instrumentation();
backExecutor.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);

huangapple
  • 本文由 发表于 2020年8月13日 22:07:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63397007.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定