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

我在 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" />

然后我有这个广播接收器:

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 11 的 Android 电视盒,确切地说,我有两个来自不同供应商的盒子,两者都只有以太网,没有 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

回答1

我将 ConnectivityService 移至 Service,它有所帮助。

相似文章

最新文章