android设置时间[随手记]

/**
	 * 设置系统时间
	 * 
	 * @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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值