From 0d2dbecb03f2391f117cb14a96a481b3d442528d Mon Sep 17 00:00:00 2001
From: 18034727885 <973609879@qq.com>
Date: 星期二, 30 六月 2026 21:29:36 +0800
Subject: [PATCH] 修复问题

---
 rxnetty/src/main/java/cn/sinata/rxnetty/CoreService.java |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/rxnetty/src/main/java/cn/sinata/rxnetty/CoreService.java b/rxnetty/src/main/java/cn/sinata/rxnetty/CoreService.java
index 2038e13..0a85625 100644
--- a/rxnetty/src/main/java/cn/sinata/rxnetty/CoreService.java
+++ b/rxnetty/src/main/java/cn/sinata/rxnetty/CoreService.java
@@ -1,10 +1,13 @@
 package cn.sinata.rxnetty;
 
-import android.app.*;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Color;
-import android.os.Build;
 import android.os.IBinder;
 import android.util.Log;
 
@@ -14,6 +17,7 @@
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.concurrent.TimeUnit;
+
 import cn.sinata.rxnetty.netStatus.NetChangeObserver;
 import cn.sinata.rxnetty.netStatus.NetStateReceiver;
 import cn.sinata.rxnetty.netStatus.NetUtils;
@@ -23,6 +27,7 @@
 import io.reactivex.netty.channel.ObservableConnection;
 import rx.Observable;
 import rx.Subscriber;
+import rx.android.schedulers.AndroidSchedulers;
 import rx.functions.Action1;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
@@ -114,12 +119,12 @@
         };
         NetStateReceiver.registerObserver(mNetChangeObserver);
         if (Config.isStartForeground) {
-            startForeground(Config.NOTIFICATION_ID,getNotification());
+            startForeground(Config.NOTIFICATION_ID, getNotification());
         }
         return START_NOT_STICKY;
     }
 
-    private Notification getNotification(){
+    private Notification getNotification() {
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
             //8.0以上创建channel
             NotificationManager notificationManager =
@@ -258,17 +263,20 @@
             return;
         }
         //reconnect
-        Observable.timer(3, TimeUnit.SECONDS).subscribe(new Action1<Long>() {
-            @Override
-            public void call(Long aLong) {
-                if (mConnection != null) {
-                    mConnection.close();
-                    mConnection = null;
-                }
-                Log.i("CoreService", "sendHeart_websocket长连接断开,重新连接");
-                connectServer();
-            }
-        });
+        Observable.timer(3, TimeUnit.SECONDS)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new Action1<Long>() {
+                    @Override
+                    public void call(Long aLong) {
+                        if (mConnection != null) {
+                            mConnection.close();
+                            mConnection = null;
+                        }
+                        Log.i("CoreService", "sendHeart_websocket长连接断开,重新连接");
+                        connectServer();
+                    }
+                }, Throwable::printStackTrace);
 
     }
 

--
Gitblit v1.7.1