android - 当我的 android 应用程序尝试连接到指定网络时,网络连接提示循环
问题描述
我是 android 开发的新手,正在尝试创建一个简单的示例应用程序,当按下按钮时连接到指定的网络。
我发现了一些其他问题的例子,但他们正在使用现在已弃用的WifiManager.addNetwork()
目前,当我在华为 P20(Android 版本 10)上进行本地测试时,会弹出连接提示,扫描并找到正确的网络,我连接,给出“连接成功”消息,然后再次弹出提示并重复,重复,重复。 ..
随着“详细”调试这些消息不断重复,因为我一直在提示连接
D/ZrHung.AppEyeUiProbe: not watching, wait.
D/ZrHung.AppEyeUiProbe: restart watching
D/ZrHung.AppEyeUiProbe: not watching, wait.
D/ZrHung.AppEyeUiProbe: restart watching
我的 onClick 调用
fun onConnectClick (view: View)
{
val wifiSpecs = WifiNetworkSpecifier.Builder()
.setSsid("SSID")
.setWpa2Passphrase("PASSWORD")
.build()
val networkRequest = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.setNetworkSpecifier(wifiSpecs)
.build()
val connectivityManager = getSystemService((Context.CONNECTIVITY_SERVICE)) as ConnectivityManager
val networkCallback = ConnectivityManager.NetworkCallback()
connectivityManager.requestNetwork(networkRequest, networkCallback)
Reply.text = "Connect Clicked"
}
我试过更换
val networkCallback = ConnectivityManager.NetworkCallback()
和
val networkCallback = object:ConnectivityManager.NetworkCallback() {
override fun onAvailable(network:Network) {
super.onAvailable(network)
connectivityManager.bindProcessToNetwork(network)
}
如其他地方所述,但没有变化
完整的 logcat 输出是:
I/e.myapplicatio: Late-enabling -Xcheck:jni
E/e.myapplicatio: Unknown bits set in runtime_flags: 0x8000
I/e.myapplicatio: Reinit property: dalvik.vm.checkjni= false
E/libc: Access denied finding property "runtime.mmitest.isrunning"
D/ActivityThread: Attach thread to application
W/ActivityThread: Application com.example.myapplication is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/chatty: uid=10270(com.example.myapplication) identical 1 line
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1421)
I/e.myapplicatio: QarthPatchMonintor::Init
I/e.myapplicatio: QarthPatchMonintor::StartWatch
I/e.myapplicatio: QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
I/e.myapplicatio: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/com.example.myapplication
I/e.myapplicatio: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
I/e.myapplicatio: QarthPatchMonintor::Run
I/e.myapplicatio: QarthPatchMonintor::Reading
I/e.myapplicatio: QarthPatchMonintor::CheckNotifyEvent
I/e.myapplicatio: QarthPatchMonintor::CheckNotifyEvent before read
I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.myapplication#10270#256
I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.myapplication#10270#0
I/AwareBitmapCacher: init processName:com.example.myapplication pid=24286 uid=10270
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@88ec3a
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@12270eb
V/ActivityThread: callActivityOnCreate
V/HwWidgetFactory: : successes to get AllImpl object and return....
I/OverScrollerOptimization: start init SmartSlideOverScroller and get the overscroller config
I/OverScrollerOptimization: get the overscroller config
W/e.myapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/e.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/ActivityThread: add activity client record, r= ActivityRecord{cf15e4 token=android.os.BinderProxy@5401765 {com.example.myapplication/com.example.myapplication.MainActivity}} token= android.os.BinderProxy@5401765
W/HiTouch_HiTouchSensor: depended package hiTouch does n't exist!
I/HiTouch_HiTouchSensor: HiTouch restricted: system app HiTouch don't exist.
D/HiTouch_PressGestureDetector: onAttached, package=com.example.myapplication, windowType=1, mHiTouchRestricted=true
I/iGraphics: [0020080c] pn: com.example.myapplication, p: 24286
I/iGraphics: [0030080c] no spt app: com.example.myapplication
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
W/Gralloc3: mapper 3.x is not supported
I/HwViewRootImpl: removeInvalidNode jank list is null
D/AwareBitmapCacher: handleInit switch not opened pid=24286
I/HwViewRootImpl: removeInvalidNode all the node in jank list is out of time
V/AudioManager: querySoundEffectsEnabled...
D/ConnectivityManager: requestNetwork and the calling app is: com.example.myapplication
D/ZrHung.AppEyeUiProbe: not watching, wait.
D/ZrHung.AppEyeUiProbe: restart watching
D/HwFrameworkSecurityPartsFactory: HwFrameworkSecurityPartsFactory in.
I/HwFrameworkSecurityPartsFactory: add HwFrameworkSecurityPartsFactory to memory.
W/libEGL: EGLNativeWindowType 0x7c3502cc10 disconnect failed
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
D/ZrHung.AppEyeUiProbe: not watching, wait.
W/libEGL: EGLNativeWindowType 0x7c3502cc10 disconnect failed
D/ZrHung.AppEyeUiProbe: restart watching
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
I/HwViewRootImpl: removeInvalidNode all the node in jank list is out of time
W/libEGL: EGLNativeWindowType 0x7c26c4b750 disconnect failed
D/ZrHung.AppEyeUiProbe: not watching, wait.
完整代码可以在这里找到
解决方案
推荐阅读
- rest - GraphQL 如何比 REST 更高效?
- r - 根据 R 中的条件添加元素 rep 的列和 nb
- facebook-graph-api - 视频尚未准备好通过 Facebook Marketing API 在广告中使用
- c - 内联汇编打印功能不起作用
- python - 内核似乎已经死了
- python - 无法使用 python 烧瓶写入文件
- swift - 如何在 Swift 中对日期进行单元测试
- php - 修复 PHP 错误 - 注意 Undefined index: url
- python - 获得意外的无限 while 循环
- mysql - MySQL查询以识别每月只有一个特定值的记录