WiFi对等发现的Android O问题 [英] Android O issues with WiFi Peer Discovery

查看:176
本文介绍了WiFi对等发现的Android O问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,该应用程序使用WiFi(直接)进行服务发现和P2P对等点发现/连接.

I am developing an Android Application that employs WiFi (Direct) for service discovery and P2P peer discovery/connection.

我的开发环境如下:-

Android Studio 3.0 Beta 4
Build #AI-171.4304935, built on August 29, 2017
JRE: 1.8.0_152-release-915-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6

我的Gradle版本:-

My Gradle build:-

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.research.wifi_direct"

        minSdkVersion 19
        targetSdkVersion 26

        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    buildTypes {

        debug {
            buildConfigField "String", "INSTANCE_NAME", "\"_vascodagama\""
            buildConfigField "String", "SERVICE_TYPE", "\"_presence._tcp\""
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:26.0.2'
    implementation 'com.android.support:recyclerview-v7:26.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    implementation 'com.yarolegovich:lovely-dialog:1.0.7'

    implementation 'io.realm:android-adapters:2.1.0'


    testImplementation 'junit:junit:4.12'

    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

我正在测试的设备包括:-

The devices I am testing on include:-

Nexus 7 - Android 6.0.1
Nexus 9 - Android 7.1.1
Samsung Tablet - Android 4.4.1
Pixel - Android 8.0.0 

服务发现在所有四个设备上都能正常工作.

The service discovery works fine on all four devices.

但是,在运行Android 8.0.0Pixel XL上,P2P对等列表始终为空. 其他三个设备以及其他杂项设备始终能够发现彼此 在我办公室附近例如三星电视和同事的个人电话等.

However the P2P Peers List is always empty on the Pixel XL running Android 8.0.0. The other three devices consistently discover each other as well as other miscellaneous devices around my office e.g. such as a Samsung TV and my colleagues personal phones etc..

我唯一能想到的是关于Android O的某些内容会阻止P2P对等方被发现. 我无法在"Android O的新功能"中看到任何内容来识别罪魁祸首

The only thing I can think of is that theres something about Android O that inhibits P2P peers being discovered. I cannot see anything in the "Whats New In Android O" to identify the culprit

有人在Android O上看到此行为吗?我究竟做错了什么?我想念什么?

Has anyone seen this behaviour on Android O? What am I doing wrong? What am I missing?

我基于我的应用程序的代码可以在这里找到

The code I am basing my application on is to be found here

https://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html https://developer.android.com/training/connect -devices-wirelessly/nsd-wifi-direct.html

我注意到的一件奇怪的事是,当我尝试使用android.net.wifi.WifiManager.WifiLock使WiFi堆栈"保持清醒状态时 我的应用程序完全停止工作.此外,我必须关闭所有设备的电源,并在卸下设备后重新启动它们. 关联的WiFiLock代码.是的...我确实添加了使用权限android:name="android.permission.WAKE_LOCK".

Something odd that I noticed was that when I tried to keep the WiFi "stack" awake using an android.net.wifi.WifiManager.WifiLock my application stopped working altogether. Further more I had to power off all my devices and restart them once I had removed the associated WiFiLock code. And yes... I did add uses-permission android:name="android.permission.WAKE_LOCK".

更新-0001

奇怪的是,当我注销广播接收器中适用于PEER_CHANGED的其他功能时,当Android O Pixel XL发现我的Nexus时,我可以看到列出的可用对等方

Whats odd is that when I log out the extras available in my Broadcast Receiver for PEER_CHANGED I can see the available peers listed as shown here when the Android O Pixel XL has discovered my Nexus

WiFiDirectBroadcastRcvr: android.net.wifi.p2p.PEERS_CHANGED<<<<<EXTRA DATA :: ------------------------START
WiFiDirectBroadcastRcvr: EXTRA DATA :: wifiP2pDeviceList 
                         Device: Nexus 7
                          deviceAddress: da:50:e6:7c:56:4e
                          primary type: 000A0050F2040005
                          secondary type: null
                          wps: 392
                          grpcapab: 0
                          devcapab: 37
                          status: 3
                          wfdInfo: WFD enabled: trueWFD DeviceInfo: 0
                          WFD CtrlPort: 0
                          WFD MaxThroughput: 0 (android.net.wifi.p2p.WifiP2pDeviceList)
WiFiDirectBroadcastRcvr: EXTRA DATA :: ------------------------FINISH

但是当我随后对requestPeers进行后续调用时,我总是收到一个空的WifiP2pDeviceList?

However when I then make my subsequent call to requestPeers I always receive an empty WifiP2pDeviceList?

case WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION:
                Log.d(TAG, "onReceive: WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION");
                mWiFiPeer2PeerCommander.requestPeers(mWifiP2pManager, mWifiP2pManagerChannel);
                break;

我应该使用传递的Extra中的WifiP2pDeviceList来打电话给requestPeers吗?

Am I supposed to use the WifiP2pDeviceList from the passed Extra an not bother to call requestPeers?

推荐答案

我遇到了同样的问题.在我的nexus 5x上,现在还有AndroidO. 而且我也总是有一个空的WifiP2pDeviceList. 我认为这是Android 6上类似问题的赋值(?) SCAN_RESULTS_AVAILABLE_ACTION在Android 6.0中返回空列表

I had the same problem. On my nexus 5x now also Android O. And I also always got an empty WifiP2pDeviceList. I think it's assign (?) with similar problem on Android 6 SCAN_RESULTS_AVAILABLE_ACTION return empty list in Android 6.0

它对我有用...

这篇关于WiFi对等发现的Android O问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆