while using flutter `esc_pos_bluetooth` showing error `Error starting scan. ` only in android 12. no problem below android 10

huangapple go评论70阅读模式
英文:

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.
&lt;uses-permission android: name=&quot;android.permission.BLUETOOTH&quot; android:maxSdkVersion=&quot;31&quot; tools:targetApi=&quot;donut&quot; /&gt;
&lt;uses-permission android: name=&quot;android.permission.BLUETOOTH_ADMIN&quot; android:maxSdkVersion=&quot;31&quot; tools:targetApi=&quot;donut&quot; /&gt;
&lt;uses-permission android: name=&quot;android.permission.BLUETOOTH_SCAN&quot; tools:targetApi=&quot;31&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; android:maxSdkVersion=&quot;31&quot; tools:targetApi=&quot;donut&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADVERTISE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_CONNECT&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_BACKGROUND_LOCATION&quot; android:maxSdkVersion=&quot;31&quot; tools:targetApi=&quot;donut&quot; /&gt;
&lt;uses-permission android: name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
.
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版本并在真实设备上使用以下清单对我有效:

    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADMIN&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_SCAN&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADVERTISE&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_CONNECT&quot; /&gt;
    &lt;uses-feature android:name=&quot;android.hardware.bluetooth&quot; android:required=&quot;true&quot;/&gt;
    &lt;uses-feature android:name=&quot;android.hardware.bluetooth_le&quot; android:required=&quot;true&quot;/&gt;

你遗漏的是uses-feature标志。在这里查看它。

你还可以阅读关于Android上低于12.0版本的蓝牙问题的信息这里

英文:

Using 0.4.1 with the following manifest on a real device works for me:

    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADMIN&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_SCAN&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADVERTISE&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_CONNECT&quot; /&gt;
    &lt;uses-feature android:name=&quot;android.hardware.bluetooth&quot; android:required=&quot;true&quot;/&gt;
    &lt;uses-feature android:name=&quot;android.hardware.bluetooth_le&quot; android:required=&quot;true&quot;/&gt;

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

huangapple
  • 本文由 发表于 2023年2月6日 19:13:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定