|
|
@@ -28,8 +28,9 @@ public class DoorService extends Service {
|
|
|
|
|
|
private static final int MSG_SEND_MSG = 1;
|
|
|
private static final int MSG_OPEN_FAIL = 2;
|
|
|
+ private static final int MSG_AUTO_CLOSE = 3;
|
|
|
|
|
|
- private DatagramSocket socket;
|
|
|
+ private static DatagramSocket socket;
|
|
|
private InetAddress serverAddress;
|
|
|
private String host;
|
|
|
private int port;
|
|
|
@@ -50,6 +51,11 @@ public class DoorService extends Service {
|
|
|
switch (msg.what) {
|
|
|
case MSG_OPEN_FAIL:
|
|
|
Toasty.error(getApplicationContext(), "解锁失败,请稍后再试").show();
|
|
|
+ break;
|
|
|
+ case MSG_AUTO_CLOSE:
|
|
|
+ status = "closed";
|
|
|
+ EventBus.getDefault().post(status);
|
|
|
+ break;
|
|
|
}
|
|
|
return true;
|
|
|
});
|
|
|
@@ -107,8 +113,13 @@ public class DoorService extends Service {
|
|
|
Log.i(TAG, "UDP result: " + result);
|
|
|
EventBus.getDefault().post(result);
|
|
|
status = result;
|
|
|
- if ("closed".equals(result)) {
|
|
|
+ if ("opened".equals(result)) {
|
|
|
mHandler.removeMessages(MSG_OPEN_FAIL);
|
|
|
+ Message msg = new Message();
|
|
|
+ msg.what = MSG_AUTO_CLOSE;
|
|
|
+ mHandler.sendMessageDelayed(msg, 10 * 1000);
|
|
|
+ } else if ("closed".equals(result)) {
|
|
|
+ mHandler.removeMessages(MSG_AUTO_CLOSE);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|