Would using six separate components for the six connections help prevent interference among them?
EDIT: please let us know, if scanning works fine repeatedly if you use the test project...
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.
To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
The test apk will scan repeatedly, although it usually only returns the one or two devices that are powered on, out of the four paired devices. Because of this, I populate the “Paired devices” listpicker with the “AddressesAndNames” block of the MIT BT extension in order to display all paired devices.
I can also toggle between the two listviews in order to display all paired devices OR all available devices, not both at the same time. This is because the screen real estate is limited and I want to have 10 or more devices to pair/unpair at one time.
The real puzzle is why it works on the ai2 Companion, but not when compiled.
what you could try is
- to move the AskForPermission block into the event Screen.Initialize
- and move the Scan method directly into the event Scan.Click
you also might want to provide a Screen.PermissionDenied event, see again the example app here https://puravidaapps.com/bluetooth.php
which device / Android version are you using for your tests?
Taifun
Tried all of your suggestions, but no go.
Still runs well in the Companion, but not in the apk version.
The device is a Lenovo tablet TB-7304F running Android 7 (Nougat).
which means, it is a permission issue...
you might want to provide a screenshot of your updated relevant blocks after you followed these suggestions
Taifun
Another symptom is that after the first (and only) scan, it is virtually impossible to select any of the elements in either listview. It’s as if the app hangs.
you are starting the Scan twice, 1) in the PermissionGranted event and 2) in the Scan.Click event…
let me suggest you to remove the PermissionGranted event completely or alternatively just display a message for the user, that the permission has been granted successfully
Taifun
OK, I removed the PermissionGranted event but nothing changes.
I don’t know where to go from here. I’d say it was a quirk of the Lenovo Tab device, except for the fact that it works perfectly well in the Companion. What could be different about the Companion environment from the installed apk?
Try your apk on a device other than your Lenovo Tab? Let us know what happens. The problem could be a device issue or an issue related to the Android version. The only way to know is to do some experimentation with different actual devices and os versions.
Yes, that makes sense. I’ll do some hunting around.
let's summarize...
- scanning repeatedly works fine if you use the test project as apk file
- scanning repeatedly works fine, if you use your project in the companion app
- scanning works only once, if you use your project as apk file
is this understanding correct?
concerning 3)
can you explain what happens step by step
a) you get the message to grant permission and you confirm
b) then you click the scan button, in the label the text "Scanning please wait" appears and after a while the result will be displayed in the listpicker
c) now you click the scan button again, so what happens here? does the text "Scanning please wait" appear? how do you know, that the second scan did not succeed?
Taifun
Yes, your summary of 1, 2 and 3 is correct.
a) The permission message appeared only once, many days ago. Since then, it has not appeared, despite being in the blocks.
b) Correct.
c) When the “scan” button is clicked the second and subsequent times, the listpicker is immediately cleared, the message “Scanning, please wait” appears briefly (for perhaps 1/4 second) then disappears.
After that, nothing happens. The listpicker remains empty.
Strangely, when run in the Companion, pressing “Scan” does not clear the listpicker immediately. The previously obtained list persists during the scan operation and is only cleared when populated by the latest data.
The apk seems to run in other Android devices, such as a Samsung Galaxy 3 and 5 and a Vivo X20A, so it looks like the cheap Lenovo Tab is not acting like a good citizen. Perhaps it’s a memory issue, but this would not explain why it runs happily in the Companion, but not when compiled.
this is normal, because the user only has to grant the permission once
so it seems to be a device specific issue
Tiafun
this is normal, because the user only has to grant the permission once
Ah, OK, that makes sense.
so it seems to be a device specific issue
It looks that way, but I'd dearly love to know why it runs perfectly well in the Companion. Does the Companion supply functionality that is missing in the app/hardware environment?
sorry, I do not know
which Android version does the device use?
Minimum API version for this extension is API version 18, which is Android 4.3 (Jelly Bean MR2).
Taifun
Sorry, just saw your reply.
The Android version on the tablet is 7.0, which is Nougat.
Perhaps the 1 GB of RAM is not enough to handle the processes, but I’d be surprised if that were the case.
Normally I wouldn’t mind if it was just this tablet that was misbehaving, but if I publish the app, I need to be sure that other devices will run it properly.
unfortunately I can't guarantee, that the extension will work on all different devices without any issues
that's life... nothing is sure...
Taifun
how can I send values like 1 and 0 when I click a certain button :>