android设置时间[随手记]

来源:互联网 发布:windows 断点续传工具 编辑:程序博客网 时间:2024/05/17 07:01
/** * 设置系统时间 *  * @param date */public static final void setSystemTime(Date date) {try {Process process = Runtime.getRuntime().exec("su");DataOutputStream os = new DataOutputStream(process.getOutputStream());DateFormat format = new SimpleDateFormat("yyyyMMdd.hhmmss");String stringTime = format.format(date);String cmd = String.format("date -s %s\n", stringTime);os.writeBytes(cmd);os.flush();os.close();} catch (Exception e) {e.printStackTrace();}}

最近在做一个应用程序,这个应用程序有根据GPS模块设置系统时间的功能,于是在网上找了上述方法,但是这个方法在第一次设置时间的时候好使,但是在第二次设置系统时间的时候就报ANR错误(有时候不能指明是什么错误,然后就莫名其妙的退出程序了),在程序调试过程中,由于代码量太大,导致不知道是哪里出现ANR错误,而且没有错误定位

错误日志:

07-27 01:04:47.050: E/InputDispatcher(1688): channel '411eb3b8 com.example.mactrotouch/com.example.mactrotouch.FullscreenActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-27 01:04:48.250: E/InputDispatcher(1688): Received spurious receive callback for unknown input channel.  fd=198, events=0x8


0 0
原创粉丝点击