ConnectivityService:ConnectivityService NetworkRequestInfo binderDied - 应用程序在失去互联网连接后死亡

ConnectivityService: ConnectivityService NetworkRequestInfo binderDied - application dies after lost internet connection

我在 AndroidManifest.xml

中拥有以下权限
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

然后我有这个 BroadcastReceiver:

public class StartAfterRebootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    if (Properties.DEBUG) Log.d(TAG, "Receiver started");
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkRequest.Builder builder = new NetworkRequest.Builder();
    connectivityManager.registerNetworkCallback(
            builder.build(),
            new ConnectivityManager.NetworkCallback() {

                @Override
                public void onAvailable(Network network) {
                    if (Properties.DEBUG) Log.d(TAG, "Receiver running after connectivity up");
                    if (Properties.DEBUG)
                        Log.d(TAG, "Receiver starts service, probably once");
                    if (!UpdateService.isCurrentlyRunning()) {
                        if (Properties.DEBUG)
                            Log.d(TAG, "Receiver UpdateService is not running, try to start");
                        UpdateService.startService(context);
                    }
                }

                @Override
                public void onLost(Network network) {
                    if (Properties.DEBUG)
                        Log.d(TAG, "Receiver not running after connectivity lost");
                    if (UpdateService.isCurrentlyRunning()) {
                        if (Properties.DEBUG)
                            Log.d(TAG, "Receiver UpdateService is running, sometimes need to redesigned stop service");
                        UpdateService.stopService(context);
                    }
                }
            }
    );
}
}

我有 Android 电视盒 Android 11,正好我有两个来自不同供应商的盒子,两者都只有以太网,没有 wifi,但其中一个都运行良好,但在另一个应用程序启动时,正确启动前台服务,当我拔出以太网电缆时,服务被正确破坏,但它的全部。应用死机 logcat 我收到这条消息:

05-18 22:05:03.444   548   852 D ConnectivityService: ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ LISTEN id=19, [ Capabilities: NOT_RESTRICTED&TRUSTED&NOT_VPN&FOREGROUND Uid: 10027 AdministratorUids: [] RequestorUid: 10027 RequestorPackageName: com.droidlogic.updater] ], android.os.BinderProxy@dc6b02d)

我做错了什么。我在这里坐了一个多星期,我看不出有任何错误。它的系统应用程序是用 android.

编译的

非常感谢。 D

我将 ConnectivityService 移至 Service,这很有帮助。