英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论