Nearby Messages API 的耗电量可能是 它使用蓝牙和其他设备资源来检测 附近的设备。为确保用户能够掌控使用体验,用户可选择启用 对话框会在用户首次访问 Nearby Messages API 时显示。 用户必须同意“附近”功能使用所需设备 资源。
仅限 BLE
如果您的应用已获得 ACCESS_FINE_LOCATION 权限,并且仅在发布和使用 BLE 期间使用 BLE 订阅人数。
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMessagesClient = Nearby.getMessagesClient(this, new MessagesOptions.Builder()
.setPermissions(NearbyPermissions.BLE)
.build());
}