英文:
while using flutter `esc_pos_bluetooth` showing error `Error starting scan. ` only in android 12. no problem below android 10
问题
在Flutter中运行esc_pos_bluetooth
时出现错误,我在清单页面中添加了如下权限。
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:targetApi="31" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
但仍然出现错误。
Error starting scan.
E/flutter (16326): [ERROR: flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Platform Exception(startscan, Need android.permission.BLUETOOTH_SCAN permission for android.content.AttributionSource@8a7ab34e: GattService register Scanner, null, null)
这个问题只在Android 10或更高版本的设备上显示。在Android 10以下的版本手机上,这一切都能顺利运行,并且可以显示附近的设备。
英文:
Showing error while running in esc_pos_bluetooth
in flutter I added permission in manifest page like this.
<uses-permission android: name="android.permission.BLUETOOTH" android:maxSdkVersion="31" tools:targetApi="donut" />
.
<uses-permission android: name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android: name="android.permission.BLUETOOTH_SCAN" tools:targetApi="31" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="31" tools:targetApi="donut" />
<uses-permission android: name="android.permission.ACCESS_COARSE_LOCATION" />
And still having the error.
Error starting scan.
.
E/flutter (16326): [ERROR: flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Platform Exception(startscan, Need android.permission.BLUETOOTH_SCAN permission for android.content.AttributionSource@8a7ab34e: GattService register Scanner, null, null)
this problem is only showing in android 10 or above devices only. under android 10 version phones support this smoothly and showing near devices also.
答案1
得分: 0
使用0.4.1
版本并在真实设备上使用以下清单对我有效:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
你遗漏的是uses-feature
标志。在这里查看它。
你还可以阅读关于Android上低于12.0版本的蓝牙问题的信息这里。
英文:
Using 0.4.1
with the following manifest on a real device works for me:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
What you are missing is the uses-feature
flag. Check it out here
You can also read about hickups für Bluetooth < 12.0 on Android here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论