?遇到这个情况是在电视机加载的时候出现的问题,加载第一个页面后,就卡住了,但是操作遥控器都可以让他进入下一页,后来就考虑了一下,模拟按键不就行了,依托这个,我就尝试用adb来模拟,就得出如下方法
private void setTimer() {
timer = new Timer();
if (timer != null) {
timer.schedule(new TimerTask() {
@Override
public void run() {
execByRuntime("input keyevent 21");
Log.e("titansys", "处理卡顿问题");
}
}, 8000);
}
}
/**
* 执行shell 命令, 命令中不必再带 adb shell
*
* @param cmd
* @return Sting 命令执行在控制台输出的结果
*/
public static String execByRuntime(String cmd) {
Process process = null;
BufferedReader bufferedReader = null;
InputStreamReader inputStreamReader = null;
try {
process = Runtime.getRuntime().exec(cmd);
inputStreamReader = new InputStreamReader(process.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
int read;
char[] buffer = new char[4096];
StringBuilder output = new StringBuilder();
while ((read = bufferedReader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
return output.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (null != inputStreamReader) {
try {
inputStreamReader.close();
} catch (Throwable t) {
//
}
}
if (null != bufferedReader) {
try {
bufferedReader.close();
} catch (Throwable t) {
//
}
}
if (null != process) {
try {
process.destroy();
} catch (Throwable t) {
//
}
}
}
}
|