Android开发者样本BluetoothLeGatt没有扫描结果

Android开发者样本BluetoothLeGatt没有扫描结果,android,bluetooth-lowenergy,Android,Bluetooth Lowenergy,我在Galaxy S9上构建并运行了Android开发者示例BluetoothLeGatt。它会运行,但不会在扫描中显示任何结果。实际上什么都没有。英国电信开通了,我有播放广告包的设备。我和他们中的一个配对,我想也许它需要那个,但还是没什么 有什么事吗?我希望在某种列表中看到办公室里基本上有一个巨大的设备列表 谢谢。请确保您在AndroidManifest.xml文件中具有以下权限 <uses-permission android:name="android.permission

我在Galaxy S9上构建并运行了Android开发者示例BluetoothLeGatt。它会运行,但不会在扫描中显示任何结果。实际上什么都没有。英国电信开通了,我有播放广告包的设备。我和他们中的一个配对,我想也许它需要那个,但还是没什么

有什么事吗?我希望在某种列表中看到办公室里基本上有一个巨大的设备列表


谢谢。

请确保您在AndroidManifest.xml文件中具有以下权限

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

广告中使用的UUID应该与扫描时使用的UUID相同。此外,请确保在扫描之前已授予您位置权限。位置处于启用状态。应用程序示例已安装,但它们不会显示在位置的隐私列表中,我猜它们从未为此设置。我从商店里下载了Microchip的蓝牙数据应用程序。它扫描得很好。如果我在设备上打开BT并扫描,我会看到可用的设备。令人费解。我刚才试过其他的蓝牙广告,也是一样的。空扫描结果。莫名其妙的是,你能提供你所遵循的示例应用程序的链接吗?当然。就是那个。但是任何扫描的连接示例。检查下面我的答案,看看它是否有效。您必须在清单文件中具有位置权限,还需要更改启动前台通知的方式。添加设置行后,您必须进入位置、应用权限,您将在拒绝列表中找到BluetoothLegat。你必须允许它。在那之后它就开始工作了。
String CHANNEL_ID = "44";
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_launcher)
                .setPriority(Notification.PRIORITY_LOW)
                .setOngoing(true)
                .setAutoCancel(false)
                .setContentTitle("Ble DEMO")
                .setContentText("BLE content text")
                .setTicker("TICKER")
                .setChannelId(CHANNEL_ID)
                .setVibrate(new long[]{0L})
                .setContentIntent(pendingIntent);
        Notification notification = builder.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "NOTIFICATION_BLE_CHANNEL_NAME", NotificationManager.IMPORTANCE_HIGH);
            channel.setDescription("NOTIFICATION_BLE_CHANNEL_DESC");
            channel.enableVibration(false);
            channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            notificationManager.createNotificationChannel(channel);
        }
        startForeground(FOREGROUND_NOTIFICATION_ID, notification);