1

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'
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
shiho
  • 31
  • 1
  • 5
  • I've removed `material:1.0.0`... while this example is pretty bad (likely broken), since it mixes GMS & HMS; you cannot have it both ways, within the same source-set - else these will clash. – Martin Zeitler May 30 '22 at 21:30

2 Answers2

0

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

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • i have all the proper permissions already, as it runs perfectly fine on my coworker's phone. – shiho May 30 '22 at 22:01
  • @shiho HarmonyOS can also run Android packages - while the `build.gradle` of the example makes no sense at all. One has to build two different packages, for example: https://stackoverflow.com/a/68801938/549372 ...all I can tell is, that your question provides irrelevant dependencies, not the least related to the ones which the example provides. – Martin Zeitler May 30 '22 at 22:08
  • @shiho Besides, your coworkers phone might also be irrelevant to the question - unless you could provide any error message which you get on the Huawei device. The permissions are the same, but the Gradle plugin and Java libraries used are whole different. – Martin Zeitler May 30 '22 at 22:26
0

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/

Zinna
  • 1,947
  • 2
  • 5
  • 20