我想发送消息(问题:如果特定文件可用或不可用)并希望从其他Android设备回答(如果文件可用:是)。为此我在本地网络上发送udp广播消息以立即询问设备然后用tcp协议发送文件,工作正常。但有时Android设备不会在屏幕上关闭udp消息。我还在广播接收器中获得了唤醒锁和多播锁,它可以检测到屏幕关闭,但它不起作用。请帮忙!谢谢..
PowerManager powerManager =
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
wakeLock.acquire();
WifiManager.MulticastLock multicastLock = wifiManager.createMulticastLock("lockWifiMulticast");
multicastLock.acquire();
WifiManager.WifiLock wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF,"MyWifiLock");
wifiLock.acquire();