@@ -83,6 +83,15 @@ public void run(){
8383 public void onCreate () {
8484 super .onCreate ();
8585 LogUtils .e ("oncreate:" +isNotificationEnabled (this ));
86+ if (!isNotificationEnabled (this )){
87+ Toast .makeText (this , "Dr.com没有通知栏权限,记得去设置里开启喔" , Toast .LENGTH_SHORT ).show ();
88+ }
89+ }
90+
91+ @ Override
92+ public void onDestroy () {
93+ super .onDestroy ();
94+ hideNotification ();
8695 }
8796
8897 private void showNotification () {
@@ -93,10 +102,11 @@ private void showNotification() {
93102 NotificationCompat .Builder mBuilder =
94103 new NotificationCompat .Builder (this )
95104 .setSmallIcon (R .mipmap .ic_launcher )
96- .setContentTitle ("Drcom正常运行中 " )
97- .setContentText ("测试 " )
98- .setTicker ("测试通知来啦 " )
105+ .setContentTitle ("Dr.com正常运行中 " )
106+ .setContentText ("能看到我就说明有网络 " )
107+ .setTicker ("Dr.com运行中 " )
99108 .setWhen (System .currentTimeMillis ())
109+ .setOngoing (false ) //用户无法滑动删除通知栏
100110 .setContentIntent (contentIntent );
101111 mNotifyMgr .notify (FOREGROUND_ID , mBuilder .build ());
102112 }
@@ -105,9 +115,7 @@ private void hideNotification(){
105115 notificationManager .cancel (FOREGROUND_ID );
106116 }
107117
108-
109118 private boolean isNotificationEnabled (Context context ) {
110-
111119 AppOpsManager mAppOps = (AppOpsManager ) context .getSystemService (Context .APP_OPS_SERVICE );
112120 ApplicationInfo appInfo = context .getApplicationInfo ();
113121 String pkg = context .getApplicationContext ().getPackageName ();
@@ -222,7 +230,7 @@ private void mainRun() {
222230 //重置端口 继续发alive包,若超过则可能是UDP丢包导致
223231 init ();
224232 if (reconnectTimes >= 2 ){
225- //第一次只重发alive失败后之后选择重新登陆
233+ //第一次只重发alive,失败后之后第二三次选择重新登陆
226234 if (!challenge (challengeTimes ++)||!login ()) {
227235 performMsgCall ("自动重新登陆失败,准备断网" );
228236 break ;
@@ -240,7 +248,7 @@ private void mainRun() {
240248 } catch (SocketTimeoutException e ) {
241249 e .printStackTrace ();
242250 performMsgCall ("通信超时:" +e .getMessage ());
243- // exception = true;
251+ exception = true ;
244252 } catch (IOException e ) {
245253 performMsgCall ("IO 异常" +e .getMessage ());
246254 exception = true ;
@@ -486,7 +494,7 @@ private boolean alive() throws IOException {
486494 performLogCall ("[rand=" +ByteUtil .toHexString (packet38 [36 ])+"|" +ByteUtil .toHexString (packet38 [37 ])+"]"
487495 +"send keep38.:" +ByteUtil .toHexString (packet38 ));
488496
489- byte [] recv = new byte [128 ];
497+ byte [] recv = new byte [64 ];
490498 client .receive (new DatagramPacket (recv , recv .length ));
491499 String logStr = String .format ("[rand={%s}|{%s}]recv Keep38. [{%s}.{%s}.{%s}.{%s}] 【{%s}】" ,
492500 ByteUtil .toHexString (recv [6 ]), ByteUtil .toHexString (recv [7 ]),
@@ -496,6 +504,7 @@ private boolean alive() throws IOException {
496504 keepAliveVer [0 ] = recv [28 ];//收到keepAliveVer//通常不会变
497505 keepAliveVer [1 ] = recv [29 ];
498506
507+ needExtra = false ; //不发送keep40_extra貌似不影响广财的上网
499508 if (needExtra ) {//每十次keep38都要发一个 keep40_extra
500509 performLogCall ("Keep40_extra..." );
501510 //--------------keep40_extra--------------------------------------------
@@ -509,7 +518,7 @@ private boolean alive() throws IOException {
509518 ByteUtil .toHexString (packet40extra [8 ]), ByteUtil .toHexString (packet40extra [9 ]),
510519 ByteUtil .toHexString (packet40extra ));
511520 performLogCall (logStr );
512- recv = new byte [512 ];
521+ recv = new byte [40 ];
513522 client .receive (new DatagramPacket (recv , recv .length ));
514523 logStr = String .format ("[seq={%s}|type={%s}][rand={%s}|{%s}]recv Keep40_extra. 【{%s}】" ,
515524 recv [1 ], recv [5 ], ByteUtil .toHexString (recv [8 ]), ByteUtil .toHexString (recv [9 ]), ByteUtil .toHexString (recv ));
@@ -527,7 +536,7 @@ private boolean alive() throws IOException {
527536 ByteUtil .toHexString (packet40_1 [8 ]), ByteUtil .toHexString (packet40_1 [9 ]),
528537 ByteUtil .toHexString (packet40_1 ));
529538 performLogCall (logStr );
530- recv = new byte [64 ];//40
539+ recv = new byte [40 ];//40
531540 client .receive (new DatagramPacket (recv , recv .length ));
532541 logStr = String .format ("[seq={%s}|type={%s}][rand={%s}|{%s}]send Keep40_1. 【{%s}】" ,
533542 recv [1 ], recv [5 ],
@@ -547,6 +556,7 @@ private boolean alive() throws IOException {
547556 ByteUtil .toHexString (packet40_2 [8 ]), ByteUtil .toHexString (packet40_2 [9 ]),
548557 ByteUtil .toHexString (packet40_2 ));
549558 performLogCall (logStr );
559+ recv = new byte [40 ];
550560 client .receive (new DatagramPacket (recv , recv .length ));
551561// performLogCall("[seq={%s}|type={%s}][rand={%s}|{%s}]recv Keep40_2. 【{%s}】", recv[1], recv[5],
552562// ByteUtil.toHexString(recv[8]), ByteUtil.toHexString(recv[9]), ByteUtil.toHexString(recv));
0 commit comments