Harmonyos 2.0.0的BLE连接

发布于 2025-02-03 11:49:11 字数 940 浏览 4 评论 0 原文

我正在使用Android Studio创建BLE扫描仪,但我似乎无法在手机上要求使用权限。我使用的是华为Harmonyos 2.0.0手机,我的同事正在使用三星Android 11手机,并且在他的手机上正常工作。

我是否需要实施特定的依赖性或为了在手机上工作吗?我看到某个地方,对于位置权限,我们需要实现一个单独的库。 ( >)。对于BLE和蓝牙,这会一样吗?

这些是我目前的依赖性:

dependencies {
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation "androidx.core:core-splashscreen:1.0.0-alpha01"
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.jjoe64:graphview:4.2.2'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

I'm using Android Studio to create a BLE Scanner but I can't seem to request for permissions on my phone. I'm using a Huawei HarmonyOS 2.0.0 phone and my coworker is using a Samsung Android 11 phone and it works fine on his phone.

Is there a specific dependency I need to implement or something in order for it to work on my phone? I saw somewhere that, for location permissions, we need to implement a separate library. (Here's the source). Would that be the same for BLE and Bluetooth?

These are my current dependencies:

dependencies {
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation "androidx.core:core-splashscreen:1.0.0-alpha01"
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.jjoe64:graphview:4.2.2'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三五鸿雁 2025-02-10 11:49:11

对于Android,BLE需要这些权限,包括对设备的扫描:

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>

一个人还应声明对死灵硬件的要求:

<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

在使用Deveco Studio为Harmonyos(本地)建立Harmonyos(本机)时,这有点不同:

它将在 entry> entry/src/main/config.json 中需要这些权限:

ohos.permission.USE_BLUETOOTH
ohos.permission.DISCOVER_BLUETOOTH
ohos.permission.LOCATION

也有一个codeLab: 如何通过ble 在设备之间启用设备之间的通信

For Android these permissions are required for BLE, including scanning for devices:

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>

And one should also declare the requirement for the neccessary hardware:

<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

When building for HarmonyOS (native) with DevEco Studio, this works a little different:
https://developer.harmonyos.com/en/docs/documentation/doc-guides/connectivity-ble-advertising-0000001051008453

And it would require these permissions in entry/src/main/config.json:

ohos.permission.USE_BLUETOOTH
ohos.permission.DISCOVER_BLUETOOTH
ohos.permission.LOCATION

There's also a codelab: How to Enable Communication Between Devices Through BLE

厌味 2025-02-10 11:49:11

您没有必须安装的特殊依赖库。我已经在我的华为Mate 30 Pro上尝试了此应用程序(下面的链接),该应用程序是Hamonyos 2.0.0手机,它可以使用。它弹出一个屏幕,要求用户启用蓝牙并允许使用该设备。

如果您仍然有问题,请提供日志文件,电话模型和Harmonyos构建号码。

在这里,我尝试了我尝试过的应用程序

https://github.com/ android/connectivity-samples/tree/master/bluetoothchat

在这里,您想了解更多信息的文章链接。 https://develper..android.com/guide.com/guide/guide/topics/topics/connectivity/connectivity/bluetoothivity/bluetooth/bluetooth

bluetooth Info的Harmonyos版本

但是,为了获得更好的用户体验,建议您使用Deveco Ide huawei huawei版本的iDE来开发特定的iDE,以适用Harmonyos而不是Android Studio

这里的链接以了解更多 https://developer.harmonyos.com/en/

There is no special dependencies libraries that you have to install. I have try this app (link below) on my Huawei Mate 30 pro which is a HamonyOS 2.0.0 phone and it works. It pop up a screen to ask user to enable Bluetooth and give it permission to use the device.

If you still have problem please provide the log file, phone model and HarmonyOS build number.

Here the link to the app I've tried

https://github.com/android/connectivity-samples/tree/master/BluetoothChat

Here the link to the article incase you want to learn more. https://developer.android.com/guide/topics/connectivity/bluetooth

Here HarmonyOS version of Bluetooth info

https://developer.harmonyos.com/en/docs/documentation/doc-guides/connectivity-bluetooth-overview-0000000000029991

However for better user experience it's recommended that you use DevEco IDE Huawei version of IDE that develop specifically to work with HarmonyOS instead of Android Studio

Here the link to learn more https://developer.harmonyos.com/en/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文