Android Bluetooth startDiscovery не работает - PullRequest
0 голосов
/ 08 февраля 2020

Я пытаюсь узнать, как использовать Bluetooth в android. Тем не менее, я уже столкнулся с проблемой, на которую не могу найти ответ. Когда я вызываю .startDiscovery () на адаптере Bluetooth, он возвращает false, что означает, что произошел сбой. Я не делаю ничего странного, я получаю BluetoothAdapter с помощью BluetoothAdapter.getDefaultAdapter () и затем вызываю .startDiscovery () для него. Я пытаюсь сделать это из фрагмента.

ACCESS_FINE_LOCATION, BLUETOOTH_ADMIN и BLUETOOTH находятся в манифесте

Пожалуйста, дайте мне знать, если мне нужно предоставить дополнительную информацию!

Logcat Выход:

2020-02-08 19:24:54.373 16129-16129/? E/Zygote: isWhitelistProcess - Process is Whitelisted
    2020-02-08 19:24:54.376 16129-16129/? E/Zygote: accessInfo : 1
    2020-02-08 19:24:54.382 16129-16129/? I/.androidairpod: Late-enabling -Xcheck:jni
    2020-02-08 19:24:54.404 16129-16129/? E/.androidairpod: Unknown bits set in runtime_flags: 0x8000
    2020-02-08 19:24:54.424 16129-16129/? D/ActivityThread: setConscryptValidator
    2020-02-08 19:24:54.425 16129-16129/? D/ActivityThread: setConscryptValidator - put
    2020-02-08 19:24:54.477 16129-16129/com.lavenderr.bluetoothtest W/ActivityThread: Application com.lavenderr.bluetoothtest is waiting for the debugger on port 8100...
    2020-02-08 19:24:54.482 16129-16129/com.lavenderr.bluetoothtest I/System.out: Sending WAIT chunk
    2020-02-08 19:24:55.483 16129-16129/com.lavenderr.bluetoothtest I/System.out: Debugger has connected
    2020-02-08 19:24:55.484 16129-16129/com.lavenderr.bluetoothtest I/System.out: waiting for debugger to settle...
    2020-02-08 19:24:56.085 16129-16129/com.lavenderr.bluetoothtest I/chatty: uid=10416(com.lavenderr.bluetoothtest) identical 3 lines
    2020-02-08 19:24:56.286 16129-16129/com.lavenderr.bluetoothtest I/System.out: waiting for debugger to settle...
    2020-02-08 19:24:56.486 16129-16129/com.lavenderr.bluetoothtest I/System.out: waiting for debugger to settle...
    2020-02-08 19:24:56.687 16129-16129/com.lavenderr.bluetoothtest I/chatty: uid=10416(com.lavenderr.bluetoothtest) identical 1 line
    2020-02-08 19:24:56.887 16129-16129/com.lavenderr.bluetoothtest I/System.out: waiting for debugger to settle...
    2020-02-08 19:24:57.088 16129-16129/com.lavenderr.bluetoothtest I/System.out: debugger has settled (1305)
    2020-02-08 19:24:57.373 16129-16177/com.lavenderr.bluetoothtest D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
    2020-02-08 19:24:57.485 16129-16129/com.lavenderr.bluetoothtest I/MultiWindowDecorSupport: updateCaptionType >> DecorView@a5bf5f5[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
    2020-02-08 19:24:57.486 16129-16129/com.lavenderr.bluetoothtest D/MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@a5bf5f5[]
    2020-02-08 19:24:57.546 16129-16129/com.lavenderr.bluetoothtest W/.androidairpod: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
    2020-02-08 19:24:57.549 16129-16129/com.lavenderr.bluetoothtest W/.androidairpod: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
    2020-02-08 19:24:57.842 16129-16129/com.lavenderr.bluetoothtest W/.androidairpod: Verification of void com.lavenderr.bluetoothtest.ui.HomeFragment.<init>() took 122.221ms
    2020-02-08 19:25:07.916 16129-16129/com.lavenderr.bluetoothtest D/BluetoothAdapter: startDiscovery
    2020-02-08 19:25:17.880 16129-16129/com.lavenderr.bluetoothtest D/BluetoothAdapter: startDiscovery
    2020-02-08 19:25:18.088 16129-16129/com.lavenderr.bluetoothtest D/ViewRootImpl@b75c09d[MainActivity]: setView = com.android.internal.policy.DecorView@a5bf5f5 TM=true MM=false
    2020-02-08 19:25:18.235 16129-16129/com.lavenderr.bluetoothtest D/ViewRootImpl@b75c09d[MainActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)0 dur=15 res=0x7 s={true 546482515968} ch=true
    2020-02-08 19:25:18.237 16129-16175/com.lavenderr.bluetoothtest D/OpenGLRenderer: createReliableSurface : 0x7f3cea3980, 0x7f3ce57000
    2020-02-08 19:25:18.253 16129-16175/com.lavenderr.bluetoothtest D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
    2020-02-08 19:25:18.313 16129-16175/com.lavenderr.bluetoothtest W/Gralloc3: mapper 3.x is not supported
    2020-02-08 19:25:18.317 16129-16175/com.lavenderr.bluetoothtest I/gralloc: Arm Module v1.0
    2020-02-08 19:25:18.453 16129-16129/com.lavenderr.bluetoothtest D/ViewRootImpl@b75c09d[MainActivity]: MSG_RESIZED_REPORT: frame=(0,0,1080,2220) ci=(0,72,0,45) vi=(0,72,0,45) or=1
    2020-02-08 19:25:18.457 16129-16129/com.lavenderr.bluetoothtest D/ViewRootImpl@b75c09d[MainActivity]: stopped(false) old=false
    2020-02-08 19:25:18.468 16129-16129/com.lavenderr.bluetoothtest D/ViewRootImpl@b75c09d[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
    2020-02-08 19:25:18.470 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: prepareNavigationBarInfo() DecorView@a5bf5f5[MainActivity]
    2020-02-08 19:25:18.470 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: getNavigationBarColor() -855310
    2020-02-08 19:25:18.479 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: prepareNavigationBarInfo() DecorView@a5bf5f5[MainActivity]
    2020-02-08 19:25:18.480 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: getNavigationBarColor() -855310
    2020-02-08 19:25:18.480 16129-16129/com.lavenderr.bluetoothtest V/InputMethodManager: Starting input: tba=com.lavenderr.bluetoothtest ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
    2020-02-08 19:25:18.481 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: startInputInner - Id : 0
    2020-02-08 19:25:18.481 16129-16129/com.lavenderr.bluetoothtest I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
    2020-02-08 19:25:18.542 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: prepareNavigationBarInfo() DecorView@a5bf5f5[MainActivity]
    2020-02-08 19:25:18.543 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: getNavigationBarColor() -855310
    2020-02-08 19:25:18.543 16129-16129/com.lavenderr.bluetoothtest V/InputMethodManager: Starting input: tba=com.lavenderr.bluetoothtest ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
    2020-02-08 19:25:18.544 16129-16129/com.lavenderr.bluetoothtest D/InputMethodManager: startInputInner - Id : 0

1 Ответ

0 голосов
/ 08 февраля 2020

После долгих поисков я наконец нашел ответ. Несмотря на то, что разрешение ACCESS_FINE_LOCATION было в моем манифесте, мне все равно нужно было «вручную» запросить разрешение. Что я сделал следующим образом:

if (ContextCompat.checkSelfPermission(this,
        Manifest.permission.ACCESS_FINE_LOCATION)
    != PackageManager.PERMISSION_GRANTED) {

    Log.i("info", "No fine location permissions")

    ActivityCompat.requestPermissions(this,
        arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
        1)
}

после выполнения этого фрагмента кода и, таким образом, получения правильного разрешения для включения обнаружения, моя проблема была решена!

...