如何解决WIFI_P2P_CONNECTION_CHANGED_ACTION 非粘性广播启动 android 10?
我正在构建一个 wifip2p 简单的聊天应用程序,并且在 android 文档 (https://developer.android.com/training/connect-devices-wirelessly/wifi-direct) 中它说
WIFI_P2P_CONNECTION_CHANGED_ACTION 指示 Wi-Fi P2P 连接的状态已更改。从 Android 10 开始,这不是粘性的。如果您的应用在注册时依赖于接收这些广播,因为它们是粘性的,请在初始化时使用适当的 get 方法来获取信息。
现在我的应用程序遇到问题,因为当我在任何 android 10 或更高版本的设备上测试我的应用程序时,它不响应此 Intent,因为他们更改了它。 我如何修改我的代码,以便我可以捕捉这些意图并获取这些信息。它说在初始化时使用“适当的 get 方法”我不知道我应该如何使用或使用什么
在我的主要活动中,这是 connectionInfoListener 代码:
wifip2pManager.ConnectionInfoListener mConnectionInfoListener = new wifip2pManager.ConnectionInfoListener() {
@Override
public void onConnectionInfoAvailable(wifip2pInfo info) {
final InetAddress groupOwnerAddress = info.groupOwnerAddress;
if (info.groupFormed && info.isGroupOwner) {
isHost = true;
status.setText("Host");
status.setTextColor(Color.parseColor("#a4c639"));
Log.d(TAG,"onConnectionInfoAvailable: this device is the HOST in the wifiDirect group");
server = new server();
server.start();
} else if (info.groupFormed) {
isHost = false;
status.setText("Client");
status.setTextColor(Color.parseColor("#a4c639"));
Log.d(TAG,"onConnectionInfoAvailable: this device is the CLIENT in the wifiDirect group");
client = new client(groupOwnerAddress);
client.start();
}
}
};
这是我的 WiFibroadcastReceiver 代码:
else if (wifip2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
// Connection state changed! We should probably do something about that
if(manager != null){
NetworkInfo mNetworkInfo = intent.getParcelableExtra(wifip2pManager.EXTRA_NETWORK_INFO);
if (mNetworkInfo.isConnected()){
manager.requestConnectionInfo(channel,mainActivity.mConnectionInfoListener);
}else {
mainActivity.status.setText("Device disconnected");
Log.d(TAG,"onReceive: connection ended. device disconnected ");
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。