HarmonyOS 鸿蒙Next 权限级别不够,怎么签名
HarmonyOS 鸿蒙Next 权限级别不够,怎么签名
权限级别不够,怎么签名 我需要使用BLE蓝牙,但是需要ohos.permission.MANAGE_BLUETOOTH这个权限
我在requestPermissions配置了,但是又需要我签名,我想问一下这个需要怎么签名?
签名分为自动签名跟手动签名, 参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/ide-signing-V13#section18815157237
自动化签名的调试方式要求您的网络可以访问Internet。如果您的应用/元服务调试时无法联网,可以在AGC中申请调试证书和Profile后,再通过手动签名的方式进行调试,具体步骤请参见手动签名方式调试HarmonyOS应用/元服务。
参考链接:https://developer.huawei.com/consumer/cn/doc/app/agc-help-harmonyos-debugapp-0000001172419675
1.是这样一个流程,AppGallery Connect地址:https://developer.huawei.com/consumer/cn/service/josp/agc/index.html
手动签名指导:https://developer.huawei.com/consumer/cn/doc/app/agc-help-harmonyos-debugapp-manual-0000001177608893
2.ohos.permission.MANAGE_BLUETOOTH权限设置:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/app-permissions-V13
试下能否解决问题
现在这个权限是系统权限,暂不支持第三方使用。
三方应用使用蓝牙功能demo:
import connection from '@ohos.bluetooth.connection';
import abilityAccessCtrl, { PermissionRequestResult, Permissions } from '@ohos.abilityAccessCtrl';
import access from '@ohos.bluetooth.access';
import { BusinessError } from '@ohos.base';
const permissions: Array<Permissions> = ['ohos.permission.ACCESS_BLUETOOTH'];
class bluetoothInfo{
deviceName:string;
deviceId:string;
constructor(deviceName:string,deviceId:string) {
this.deviceName = deviceName
this.deviceId = deviceId
}
}
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
@State@Watch('watch') arr: bluetoothInfo[] = []
aboutToAppear(): void {
this.reqPermissionsFromUser(permissions)
}
watch(){
}
reqPermissionsFromUser(permissions: Array<Permissions>): void {
let context: Context = getContext(this) as Context;
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
// requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => {
let grantStatus: Array<number> = data.authResults;
let length: number = grantStatus.length;
for (let i = 0; i < length; i++) {
if (grantStatus[i] === 0) {
// 用户授权,可以继续访问目标操作
} else {
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
return;
}
}
// 授权成功
}).catch((err: BusinessError) => {
console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
})
}
build() {
Row() {
Column() {
Button("打开蓝牙")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(()=>{
let state = access.getState() //检测蓝牙开启状态
if(state == 0){
access.enableBluetooth(); //打开蓝牙
}
})
Button("关闭蓝牙")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(async ()=>{
let state = access.getState() //检测蓝牙开启状态
if(state == 2){
await access.disableBluetooth()
}
this.arr = []
connection.stopBluetoothDiscovery();
})
Button("设置可被扫描")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(async ()=>{
let state = access.getState() //检测蓝牙开启状态
if(state == 0){
await access.enableBluetooth(); //打开蓝牙
}
connection.setBluetoothScanMode(connection.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
})
Button("扫描可连接设备")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(async ()=>{
let state = access.getState() //检测蓝牙开启状态
if(state == 0){
await access.enableBluetooth(); //打开蓝牙
}
try{
connection.on('bluetoothDeviceFind', (data: Array<string>)=>{
for(let i = 0;i<data.length;i++){
let name = connection.getRemoteDeviceName(data[i])
let k = true
for(let j = 0;j<this.arr.length;j++){
if(this.arr[j].deviceId==data[i]){
k =false
break
}
}
if(k){
if(name==""){
this.arr.push(new bluetoothInfo(data[i],data[i]))
}else {
this.arr.push(new bluetoothInfo(name,data[i]))
}
}
}
let k = this.arr
console.log('arr data:' +JSON.stringify(this.arr));
});
connection.startBluetoothDiscovery();
} catch (e) {
console.log(e)
}
})
List({ space: 20, initialIndex: 0 }) {
ForEach(this.arr, (item: bluetoothInfo) => {
ListItem() {
Text(item.deviceName)
.width('100%').height(100).fontSize(16)
.textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF)
}.onClick(()=>{
connection.pairDevice(item.deviceId)
})
})
}
}
.width('100%')
}
.height('100%')
}
onReceiveEvent(data: Array<string>) {
// for(let i = 0;i<data.length;i++){
// let name = connection.getRemoteDeviceName(data[i])
// this.arr.push(new bluetoothInfo(name,data[0]))
// }
let name = connection.getRemoteDeviceName(data[0])
try{
this.onReceiveEvent(data)
} catch (e) {
console.log(e)
}
console.log('data length' + data.length);
}
}