BLE app works in AI companion mode but not as an apk!

317 views
Skip to first unread message

KJV

unread,
Mar 1, 2019, 6:49:11 AM3/1/19
to MIT App Inventor Forum
Hi,

Recently, I have been facing issues with apps that I develop on MIT app inventor platform.

All these apps use BLE extension and seems to work well in AI companion mode but not when built as an apk!

I have developed multiple apps using the BLE extension and all work. I have used the same base code and added additional functionality for the latest apps. 
I have no clue what is the issue!

Any help is highly appreciated.


Thanks and Best Regards,
KJV

Chris Ward

unread,
Mar 1, 2019, 7:13:43 AM3/1/19
to MIT App Inventor Forum
Hi KJV

seems to work well in AI companion mode but not when built as an apk

By that, it sounds as though you mean you do not see an immediate or catastrophic failure in the APK versions but things go wrong after a while?

The possibilities are almost endless but the most common cause of issues are Screen management and infinite loops, both which cause the App to exceed it's allocated memory. There are also distinct file path differences between Companion mode and APK, so if you are saving/reading files that could be an issue.

More than that, difficult to say because we have not seen your blocks!

Follow this simple guide: https://www.professorcad.co.uk/appinventortips#TipsForum  and then we should have enough info to help you more.

This link is a list of things that can make an APK build fail, but depending on App size some factors are relevant even if the App does build.

KJV

unread,
Mar 1, 2019, 12:32:32 PM3/1/19
to MIT App Inventor Forum
Thanks Chris.

Will try the tips. Appreciate the help.

Regards,
KJV

KJV

unread,
Mar 4, 2019, 12:27:49 AM3/4/19
to MIT App Inventor Forum
Hi Chris,

In this app, I enable and populate a list picker with all the Bluetooth devices visible. The issue I am facing is that though the Bluetooth is enabled and there are Bluetooth devices available, the list picker stays disabled when the built apk is run but works fine when the app is run from the AI companion.

I have attached the images of the relevant blocks.

What do you think is causing this?


Thanks and Regards,
KJV
1.PNG
2.PNG

KJV

unread,
Mar 4, 2019, 1:16:34 AM3/4/19
to MIT App Inventor Forum
Hi,

Another observation is that all BLE apps that were built prior to november last year work fine.
I tried rebuilding one that I last built in November and that doesn't work anymore when built as an app now!

It shows that same behaviour as I mentioned in the previous post (the list picker stays disabled even when Bluetooth is enabled and there are devices available)!

Any thoughts on what is hapenning?


Thanks in advance.

Regards,
KJV

Chris Ward

unread,
Mar 4, 2019, 12:34:11 PM3/4/19
to MIT App Inventor Forum
Hi KJV

That's pretty strange! Can you post your project file here?
https://www.professorcad.co.uk/appinventortips#tipaia    How to attach a Project File (.aia) to your Forum Post

Evan Patton

unread,
Mar 4, 2019, 6:49:50 PM3/4/19
to MIT App Inventor Forum
Have you upgraded the BLE extension to version 20181124? On Dec 1st of last year we deployed the SDK 26 change, which affected how permissions are handled on Android 6.0 and higher. This adversely affects older versions of BLE because BLE scanning starting with Android 6.0 requires that apps request access to coarse location data. The old versions of the BLE extension aren't aware of this, so they silently fail in compiled apps. So why does it work in the companion? Well, when the companion gets upgraded via the store from the old version to the new version it is automatically granted all of the permissions it had prior to that release, which includes location. This allows the BLE scan operation to proceed without hinderance. However, freshly compiled apps will need location permission granted to work. The new BLE extension knows this and does the appropriate checks to get permission from the user if needed.

Regards,
Evan

Chris Ward

unread,
Mar 4, 2019, 6:55:23 PM3/4/19
to MIT App Inventor Forum
Hi Evan

The new BLE extension knows this and does the appropriate checks to get permission from the user if needed.

Evan Patton

unread,
Mar 4, 2019, 7:28:55 PM3/4/19
to MIT App Inventor Forum
Hi Chris,

Based on my reading of that post, the person didn't have location services turned on at all. We can't do that for them. This is simply to prompt for location permission, which is something different from prompting the user to turn on location services. I don't have enough information to assess whether BLE scanning should/should not work if location services are off (my assumption is that it should, but I haven't looked at the sources to see what Android actually does in this case).

Regards,
Evan

Chris Ward

unread,
Mar 4, 2019, 7:49:24 PM3/4/19
to MIT App Inventor Forum
Hi Evan

It would seem to be the case that Google Location Services must be switched on. It can be done via Activity Starter.

Evan Patton

unread,
Mar 4, 2019, 8:38:18 PM3/4/19
to MIT App Inventor Forum
I highly doubt that is a hard requirement given that we run workshops with Amazon Kindles and they do not have Google Location Services. I also run builds of LineageOS/Cyanogenmod as well without Google services and that seems to be fine. It would be good to clarify whether its Google's services or the general location services that need to be on; my guess is yes to the latter but no to the former.

Regards,
Evan

Chris Ward

unread,
Mar 4, 2019, 9:26:08 PM3/4/19
to MIT App Inventor Forum
Hi Evan

Ah yes, you are correct - general location services

location services.png


We use Blocks as above (not sure what the .AfterActivity result returns) to ensure that the BLE Scan finds the target device.




KJV

unread,
Mar 5, 2019, 12:35:46 AM3/5/19
to MIT App Inventor Forum
Hi Evan,

I updated the BLE extension to the latest one and all works fine now! Thanks!

Thanks Chris!


Have a great day!


Regards,
KJV

KASSIM SAMJI

unread,
Nov 16, 2019, 5:37:56 PM11/16/19
to MIT App Inventor Forum
took me hours to find a solution here,

my location services was off

Thanks Chris
Reply all
Reply to author
Forward
0 new messages