【问题标题】:Android: Wifi P2P list is not being updated properlyAndroid:Wifi P2P 列表未正确更新
【发布时间】:2016-05-08 21:26:05
【问题描述】:

我正在实现一个应用程序,我必须在其中发现使用 WiFi p2p 的设备并记录有关每个检测到的设备的一些数据。我遇到的问题是,当设备从联机到脱机时,WifiP2pDeviceList 没有更新,因此它会删除此设备。但是,当检测到新设备时,它通常会添加到列表中。那么我的代码有什么问题呢?

我已经看过这篇文章 (WIFI P2P discovery list is not getting refreshed?),它与我所拥有的不同。

 /**
 * A Table of devices that displays all peers and shows the corresponding
 * info about them.
 */
public class DevicesTable extends Fragment implements PeerListListener {

    protected static List<WifiP2pDevice> peers = new ArrayList<WifiP2pDevice>();
    View mContentView = null;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContentView = inflater.inflate(R.layout.table, null);
        return mContentView;
    }

    /**
     * @return this device
     */
    public WifiP2pDevice getDevice() {
        return device;
    }

    @Override
    public void onPeersAvailable(WifiP2pDeviceList newPeers) {
        ClientActivity x = (ClientActivity) ClientActivity.context;
        if (!x.wifiP2pScanThread.isScanning()) {
            return;
        }
        peers.clear();
        peers.addAll(newPeers.getDeviceList());
        ArrayList<String> onlinemacs = new ArrayList<>();
        if (peers.size() == 0) {
            Log.d(ClientActivity.TAG, "No devices found");
        } else {
            for (WifiP2pDevice dev : peers) {
                //do something
            }
        }
     }
 }

【问题讨论】:

    标签: android wifip2p


    【解决方案1】:

    我尝试了许多建议重新初始化 wifip2p managerchannel 或调用 peers.clear() 的替代方法,但它们都不起作用。 然后我遇到了这个(完美)explanation 正在发生的事情,它说列表将在特定时间段后(大约一分钟,这取决于电话)被清除,并且没有可行的方法来使用可用的软件。请注意,手动关闭/打开 Wifi 会重置列表(以及几乎所有其他与 wifi 相关的设置),但这根本不实用。

    所以简而言之,没有办法以编程方式清除以前不可用的对等点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 2019-03-28
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      相关资源
      最近更新 更多