Closed noebt closed 2 years ago
I have the same problem, to temporarily correct what I did was directly edit the plugin.
blue_thermal_printer's AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="id.kakzaki.blue_thermal_printer">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!-- Needed only if your app looks for Bluetooth devices.
You must add an attribute to this permission, or declare the
ACCESS_FINE_LOCATION permission, depending on the results when you
check location usage in your app. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
</manifest>
Also BlueThermalPrinterPlugin.java:
case "getBondedDevices":
try {
final String[] BLE_PERMISSIONS = new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
};
final String[] ANDROID_12_BLE_PERMISSIONS = new String[]{
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.ACCESS_FINE_LOCATION,
};
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(activity,
Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(activity,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity,
ANDROID_12_BLE_PERMISSIONS, REQUEST_BLE_12);
pendingResult = result;
break;
}
} else {
if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(activity,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity,
BLE_PERMISSIONS, REQUEST_COARSE_LOCATION_PERMISSIONS);
pendingResult = result;
break;
}
}
//Original code to request permissions
/*if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity,
new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, REQUEST_COARSE_LOCATION_PERMISSIONS);
pendingResult = result;
break;
}*/
getBondedDevices(result);
} catch (Exception ex) {
result.error("Error", ex.getMessage(), exceptionToString(ex));
}
break;
@SanabriaDDi It worked!! Thanks a lot, I've spent hours trying to solve it 👍
@SanabriaDDi I have tried the code but i ran into this error
C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:270: error: cannot find symbol Manifest.permission.permission.ACCESS_COARSE_LOCATION, ^ symbol: variable permission location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:275: error: cannot find symbol Manifest.permission.BLUETOOTH_SCAN, ^ symbol: variable BLUETOOTH_SCAN location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:276: error: cannot find symbol Manifest.permission.BLUETOOTH_CONNECT, ^ symbol: variable BLUETOOTH_CONNECT location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:280: error: package Build does not exist if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ^ C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:280: error: package Build does not exist if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ^ C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:283: error: cannot find symbol Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED || ^ symbol: variable BLUETOOTH_SCAN location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:285: error: cannot find symbol Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ^ symbol: variable BLUETOOTH_CONNECT location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:290: error: cannot find symbol ANDROID_12_BLE_PERMISSIONS, REQUEST_BLE_12); ^ symbol: variable REQUEST_BLE_12 location: class BlueThermalPrinterPlugin Note: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 8 errors
FAILURE: Build failed with an exception.
@SanabriaDDi I have tried the code but i ran into this error
C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:270: error: cannot find symbol Manifest.permission.permission.ACCESS_COARSE_LOCATION, ^ symbol: variable permission location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:275: error: cannot find symbol Manifest.permission.BLUETOOTH_SCAN, ^ symbol: variable BLUETOOTH_SCAN location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:276: error: cannot find symbol Manifest.permission.BLUETOOTH_CONNECT, ^ symbol: variable BLUETOOTH_CONNECT location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:280: error: package Build does not exist if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ^ C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:280: error: package Build does not exist if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ^ C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:283: error: cannot find symbol Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED || ^ symbol: variable BLUETOOTH_SCAN location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:285: error: cannot find symbol Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ^ symbol: variable BLUETOOTH_CONNECT location: class permission C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java:290: error: cannot find symbol ANDROID_12_BLE_PERMISSIONS, REQUEST_BLE_12); ^ symbol: variable REQUEST_BLE_12 location: class BlueThermalPrinterPlugin Note: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\blue_thermal_printer-1.2.0\android\src\main\java\id\kakzaki\blue_thermal_printer\BlueThermalPrinterPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 8 errors
FAILURE: Build failed with an exception.
I have this problem now, how did you fix it?
@giullianocht , fix for me
ActivityCompat.requestPermissions(activity, ANDROID_12_BLE_PERMISSIONS, 1);
Still got "lacks permission android.permission.BLUETOOTH" on it even after i follow the answers, it's not fixed
Still got "lacks permission android.permission.BLUETOOTH" on it even after i follow the answers, it's not fixed
@louisergi1 have follow this? https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
Still got "lacks permission android.permission.BLUETOOTH" on it even after i follow the answers, it's not fixed
@louisergi1 have follow this? https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
actually nvm i need to add tools resource in
Still got "lacks permission android.permission.BLUETOOTH" on it even after i follow the answers, it's not fixed
@louisergi1 have follow this? https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
actually nvm i need to add tools resource in ... my bad... and thank you so much for the response
welcome
I have the same problem, to temporarily correct what I did was directly edit the plugin.
blue_thermal_printer's AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="id.kakzaki.blue_thermal_printer"> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Request legacy Bluetooth permissions on older devices. --> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <!-- Needed only if your app looks for Bluetooth devices. You must add an attribute to this permission, or declare the ACCESS_FINE_LOCATION permission, depending on the results when you check location usage in your app. --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <!-- Needed only if your app makes the device discoverable to Bluetooth devices. --> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <!-- Needed only if your app communicates with already-paired Bluetooth devices. --> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> </manifest>
Also BlueThermalPrinterPlugin.java:
case "getBondedDevices": try { final String[] BLE_PERMISSIONS = new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, }; final String[] ANDROID_12_BLE_PERMISSIONS = new String[]{ Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.ACCESS_FINE_LOCATION, }; if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(activity, ANDROID_12_BLE_PERMISSIONS, REQUEST_BLE_12); pendingResult = result; break; } } else { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(activity, BLE_PERMISSIONS, REQUEST_COARSE_LOCATION_PERMISSIONS); pendingResult = result; break; } } //Original code to request permissions /*if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, REQUEST_COARSE_LOCATION_PERMISSIONS); pendingResult = result; break; }*/ getBondedDevices(result); } catch (Exception ex) { result.error("Error", ex.getMessage(), exceptionToString(ex)); } break;
How to do this, how can find this plugin
@giullianocht , fix for me
ActivityCompat.requestPermissions(activity, ANDROID_12_BLE_PERMISSIONS, 1);
can you show the code complete plis?
@giullianocht , fix for me
ActivityCompat.requestPermissions(activity, ANDROID_12_BLE_PERMISSIONS, 1);
can you show the code complete plis?
same like @SanabriaDDi provided, but change REQUEST_BLE_12 to 1
I hope this is solved on the latest version
Hi, I'm implementing thermal printing in Android. I did everything as in the example and added the bluetooth permissions in the manifest (as shown in the official documentation).
The thing is, the printer is found correctly, but when I try to connect to it, an error shows:
I have set the targetSDK to both 30 and 31, did flutter clean and pub get a couple of times and I keep getting the same error. I don't understand why, my manifest has the correct permissions. I am using an Android 12 device. Thanks.