Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth Serial Permissions Issue on Android 12 #454

Open
bevinGithub opened this issue Nov 9, 2022 · 18 comments
Open

Bluetooth Serial Permissions Issue on Android 12 #454

bevinGithub opened this issue Nov 9, 2022 · 18 comments

Comments

@bevinGithub
Copy link

I need assistance with the Bluetooth Serial plugin, when l check for bluetooth.isEnable it returns Ok or is Disabled which is correct. If l try to use any other functions for example List or discoverUnpaired l get the error below
ERROR
"Need android.permission.BLUETOOTH_SCAN permission for AttributionSource { uid = 10467, packageName = com.fire.service.app, attributionTag = null, token = android.os.BinderProxy@a208f16, next = null }: Starting discovery."

Your assistance will be much appreciated.

Below is my environment
Ionic:
Ionic CLI : 6.20.1
Ionic Framework : @ionic/angular 6.2.2
@angular-devkit/build-angular : 13.0.4
@angular-devkit/schematics : 13.0.4
@angular/cli : 13.0.4
@ionic/angular-toolkit : 5.0.3

Cordova:
Cordova CLI : 11.0.0
Cordova Platforms : android 10.1.2
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 14 other plugins)

Utility:
cordova-res : 0.15.4
native-run (update available: 1.7.1) : 1.5.0

System:
NodeJS : v14.15.4 (C:\Program Files\nodejs\node.exe)
npm : 6.14.10
OS : Windows 10

@lapisanlangit
Copy link

same with me.. any solution?

@bevinGithub
Copy link
Author

No response yet

@lapisanlangit
Copy link

oh my god.. i need this solution soon

@bevinGithub
Copy link
Author

bevinGithub commented Nov 17, 2022

same here brother been almost a month of researching as l can only connect phone to ble devices but l want phone to phone

@jabiinfante
Copy link

Hi!

We have managed to have this plugin working on Android 12, etc...

The solution is yet not well tested but you might find it usefull.

Remember to add these permissions on your app's AndroidManifest.xml

  <!--BLUETOOTH PERMISSION-->
  <uses-permission android:name="android.permission.BLUETOOTH" tools:replace="android:maxSdkVersion" android:maxSdkVersion="30" />
  <!-- Needed only if your app looks for Bluetooth devices. If your app doesn't use Bluetooth scan results to derive physical location information, you can strongly assert that your app doesn't derive physical location. -->
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
       android:usesPermissionFlags="neverForLocation"
       tools:targetApi="s" />
  <!-- Needed only if your app communicates with already-paired Bluetooth devices. -->
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  <!-- Needed only if your app uses Bluetooth scan results to derive physical location. -->
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

cordova-plugin-bluetooth-serial+0.4.7.patch.zip

(The patch is generated and can be applied using patch-package.

@brandomcombr
Copy link

I change the AndroidManifest.xml with this suggestions, but tags tools:replace="android:maxSdkVersion" and tools:targetApi="s", doesnt find in my project, after removing this tags my project starting in debug mode, but when you start bluetooth the error appears
I/ViewRootImpl@1a9ba7c[MainActivity]: stopped(false) old=false D/CordovaActivity: Resumed the activity. E/PluginManager: Uncaught exception from plugin java.lang.SecurityException: Permission Denial: starting Intent { act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.android.settings/.bluetooth.RequestPermissionActivity } from ProcessRecord{1a7314 513:br.com.brandom.comandacloud/u0a632} (pid=513, uid=10632) requires android.permission.BLUETOOTH_CONNECT at android.os.Parcel.createExceptionOrNull(Parcel.java:2438) at android.os.Parcel.createException(Parcel.java:2422) at android.os.Parcel.readException(Parcel.java:2405) at android.os.Parcel.readException(Parcel.java:2347) at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2897) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1743) at android.app.Activity.startActivityForResult(Activity.java:5473) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597) at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:359) at android.app.Activity.startActivityForResult(Activity.java:5431) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583) at org.apache.cordova.CordovaInterfaceImpl.startActivityForResult(CordovaInterfaceImpl.java:69) at com.megster.cordova.BluetoothSerial.execute(BluetoothSerial.java:214) at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:117) at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) at org.apache.cordova.PluginManager.exec(PluginManager.java:146) at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loopOnce(Looper.java:186) at android.os.Looper.loop(Looper.java:313) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.wm.ActivityTaskSupervisor.checkStartAnyActivityPermission(ActivityTaskSupervisor.java:1334) at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:1275) at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:906) at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1886) at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1757) I/chromium: [INFO:CONSOLE(43427)] "ERROR Error: Uncaught (in promise): Permission Denial: starting Intent { act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.android.settings/.bluetooth.RequestPermissionActivity } from ProcessRecord{1a7314 513:br.com.brandom.comandacloud/u0a632} (pid=513, uid=10632) requires android.permission.BLUETOOTH_CONNECT", source: https://localhost/vendor-es2015.js (43427) I/IMM_LC: hsifw() - flags=0, caller=android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow:1858 org.chromium.content.browser.input.ImeAdapterImpl.f:40 org.chromium.content.browser.input.ImeAdapterImpl.updateState:32 android.os.MessageQueue.nativePollOnce:-2 android.os.MessageQueue.next:335 I/IMM_LC: hideSoftInputFromWindow - mService.hideSoftInput

@brandomcombr
Copy link

I create a fork this repo and do changes necessary for working in my project
https://github.com/brandomcombr/BluetoothSerial

@lapisanlangit
Copy link

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

@giuseppelanzi
Copy link

Coincidentally i was doing a very similar thing of @brandomcombr, in my fork https://github.com/giuseppelanzi/BluetoothSerial.

I'm posting this message only because I added something.
I don't like the fact that the plugin is always asking for fine location permission. That should be used if I need to determine the physical position of the device, which I don't. So I added the boolean parameter fineLocation to discoverUnpairedDevices.

Hope it helps if someone is struggling for a similar reason.

@lapisanlangit
Copy link

lapisanlangit commented Dec 11, 2022

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

i have found new problem again.. if use device with Android 12 => working properly but if used device Android 11 getting error "error search location permission is required to discover unpaired device"

I also tried https://github.com/giuseppelanzi/BluetoothSerial .. but still have same error.. problem is using Android 11, can you help me guys?

@pmlodawski
Copy link

pmlodawski commented Dec 13, 2022

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

i have found new problem again.. if use device with Android 12 => working properly but if used device Android 11 getting error "error search location permission is required to discover unpaired device"

@lapisanlangit, please try brandomcombr#1

@shoerofi
Copy link

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

i have found new problem again.. if use device with Android 12 => working properly but if used device Android 11 getting error "error search location permission is required to discover unpaired device"

@lapisanlangit, please try brandomcombr#1

yeah, this is working on my android 11. thanks

@emilkitua
Copy link

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

i have found new problem again.. if use device with Android 12 => working properly but if used device Android 11 getting error "error search location permission is required to discover unpaired device"

@lapisanlangit, please try brandomcombr#1

yeah, this is working on my android 11. thanks

How did you implement this on your project? I am still facing the challenge. I even replaced the package with (brandomcombr#1) still doesn't work

@shoerofi
Copy link

shoerofi commented Mar 5, 2023

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

i have found new problem again.. if use device with Android 12 => working properly but if used device Android 11 getting error "error search location permission is required to discover unpaired device"

@lapisanlangit, please try brandomcombr#1

yeah, this is working on my android 11. thanks

How did you implement this on your project? I am still facing the challenge. I even replaced the package with (brandomcombr#1) still doesn't work

I am using cordova. I just change the git url in package.json
In my capacitor project I use the original plugin. No problem at all.

@Deliana90
Copy link

I create a fork this repo and do changes necessary for working in my project https://github.com/brandomcombr/BluetoothSerial

awesome this is working!!!.. i have searched all cordova bluetooth library and tried it..but no luck.. thank you very much @brandomcombr

i have found new problem again.. if use device with Android 12 => working properly but if used device Android 11 getting error "error search location permission is required to discover unpaired device"

@lapisanlangit, please try brandomcombr#1

yeah, this is working on my android 11. thanks

How did you implement this on your project? I am still facing the challenge. I even replaced the package with (brandomcombr#1) still doesn't work

I am using cordova. I just change the git url in package.json In my capacitor project I use the original plugin. No problem at all.

what package.json looks like, and how to import and use it. example code pls.

@lajith111
Copy link

lajith111 commented Apr 10, 2024

Some one please share package.json for change project url to brandomcombr#1

so that i canuse in adroid 13

EDIT:package.json current


 "@awesome-cordova-plugins/bluetooth-serial": "^6.6.0",
 "cordova-plugin-bluetooth-serial": "^0.4.7",

@emilkitua
Copy link

during installation

use: ionic cordova plugin add https://github.com/brandomcombr/BluetoothSerial
instead of ionic cordova plugin add cordova-plugin-bluetooth-serial

@lajith111
Copy link

Thank you very much @emilkitua .. since long time I am manually coping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants