2014년 12월 5일 금요일

image sprite sizing: fill parent

I tried to set an imagesprite to have height set to fill parent and width automatic, but the size seems to be automatic for both height and width.

Here is a summary of the settings:

the screen is set to portrait, not scrollable.
The canvas is set to fill parent for both height and width.
The imagesprite has x and y set to 0, height to fill parent and width to automatic. 

The sprite appears in the correct position, but isn't sized correctly.

I've had issues sizing components and saw that there were hints to enable a timer in screen initialize because a delay may be needed to allow the components to size correctly. I tried adding code to set the sizes again programatically because the properties didn't seem to be working. I set the timer interval to 1 second and catch the timer event. Then I set the imagesprite's height to -2 and width to -1, but it still seems to have no effect. 

Does fill parent work for image sprites?



What you could do, is set the height of the image sprite to be the screen height during initialization. Be aware though, if you want the width to stay in proportion, you have to calculate what it should be, because AI2 does not keep image proportions.



Yes, I understand how I could do that; set height and width to automatic and then do the calculation. But I'm teaching programming with middle school students and would like to use the facilities that are available in app inventor and have an explanation on why this isn't working. Should the fill parent option work or is this a bug? 



My apologies. Do you have a simple .aia that I can look at?
Maybe it is a bug, but i would like to check in the next release, which is all about screen sizes and so on.



Please post it to the forum, then also someone else could have a look at it.



I had a project with the same problem, and at MIT they acknowledged that it is a bug. It will be fixed in a next release. Thanks for posting it.


How to find road at Google maps API v3 (AI2 Tutorial 7.Android, Where's My Car?

recently, google maps upgrade v2 to v3 

I don't show map in Tutorial7 and don't find road

If I know A and B latitude and longitude how can I find road A from B on map, like past

plz, help me



This simple code works for the locations shown:


It is possible that Google Map Directions is turned off in your part of the World.



I tried that then appear this picture






















don't appear the map
how to solve this problem

in times past, appear the map but after Google Map v3 don't appear
plz help OTL



There are some issues here.  Perhaps we can figure them out.

1) If you input the two locations shown in the example, does your app resolve the code with a map as shown?   The code should provide a route if run from anywhere using the latitude and longitude in my prior post.

2) If the code with the 37.565,-120.9895 coordinates shows the image, and the path on your emulator or device, it demonstrates the code works correctly on your device for that location.  On my emulator, when the code runs, I am asked to complete the action with Chrome or Maps; then it asks if I want a map or navigation.  If I select map, I get the route shown.   Do you?

3) if I run the code with two coordinate set within the city of Seoul (the Button3 code block); the image is blocked for me too (no route found) when I select a means of transport other than Walking.  If I select Walking, I get this image when i selected Maps (instead of the browser):
I got this image twice.   I tried using the same code later and Google would not provide a walking route either.

I ran the code same code, but selected Browser (instead of Maps) and got this image:
which is what you see.

   I suspect that some of the navigation capability of Google Android is turned-off for some geographical areas.   Is that possible?  The message I see shows my AI2 code does not provide directions in Seoul (except for one instance) and the behavior is erratic... The message I got that this is beta code. Also, if I use the bus icon, I  a bus schedule/ route in text is displayed but not a map.  Strange behavior. (However, if I select Bus on the US map, I do not get a map display so I expect that is the new way Google is rendering the bus route information.

4) What happens if you use Google's Map app to find a route?

Google has made some very significant changes in how its Map apps work in the past few months; mainly cosmetic changes but it appears there are also unannounced changes to the Map API.

Are you running this code on an emulator or a device?   If a device, what kind and model?     Have you tried using it after building an apk?   That might give you a different result.  Why the AI2 code works with US Google Maps and not maps in your country is strange.  I am trying to research this.   I suspect it might have something to do with what versions of Google Maps work with Google's new features.  It might be the map set in your area is incompatible with Google's newest Map API.



1) map is not shown

2) i can't select map, only shown like your 3th image

3) If i select walking, i get image that no routes found

4) i want to find a route by Google's Map API
   I am using device-Pantech VEGA R3, IM-A850S/K/L
 result is same after building an apk


Testing Apps on virtual machine VS emulation

trying to improve testing applications App, I've done test with a virtual machine and putting on Android86x.

The resultats are positive, since the loading speed and performance are much better than with the emulator. You can see it in: http://youtu.be/OR_rqZ2Z4ZE

I've found a problem with AI companion, the aplication has been installed only works if there is wifi connection. Otherwise not work.

Androidx86 normal facilities, no wifi connection by default.

How do I fix that?





I use the emulators from Genymotion, and connect with them using the "USB" choice under the Connect menu.  You cannot because the emulators aren't connecting via WiFi... 

I also see that your stock emulator is running the 2.11 version of the companion, and you're bypassing the update.  You're 10 or more versions behind on that emulator, which will cause ALL sorts of problems.




the problem is that the emulator on Linux, there is no way to upgrade to version 2.23 .

Anyway the problem is that the AI try Companion accept both wifi connection , such as Ethernet .

Anyway I found a version that simulates if wifi , if not the same company gennymotion.

Problems with Split

I need help!
I have a Arduino Board and two sensors, a temperature sensor and pH sensor. Both sensors send one string information with pH and temperature, separated with a comma, by a Bluetooth module. Ex.: "11.20,23.00" (ph,temperature).
I must divide this string in two values. This two values I must insert in two differents constants (attributs). Ex.: 11.20 in pHValue and 23.00 in tempValue.
Anyone could help me please. How can I do this in MIT App Inventor 2? I'm very worried about this.



Try:





I put the "11.20,23.00"  in a label for the example.  Split converts the comma separate values and converts them to a List.  The list is converted to its components.

Does this work for you?



An erro has occorred. Did you ever see this? Follow bellow:












That value is missing a comma, so you're trying to get the second element of the list but the list only has one element.



It's done! Tnks guys!!!!

Tnks Enis and Steve!



It appears what you get from bluetooth is already a list ... your example  showed "11.20,23.00"   it appears what you are getting is (11.20,23.00)   which is already in list format.

Do a DoIt on you blocks to see what is happening.


Setting up Tablet for multiple users

Any suggestions on the best way to set up a few tablets for student use?  I want to leave them pretty open, but I also want to be able to wipe profiles easily.

I have a few Nexus 7 tablets (2013).


Recursive calls of procedures lead to undefined runtime errors, can you fix it?

I programed a Minesweeper game like you know from Mircrosoft Windows. I also liked to have the comfort to open surrounding areas when clicking on an area with no bombs in its neighbourhood. By doing so, a procedure is called recursively serval times, until all opened "border" areas have bombs in their neighbourhood. 
My program works fine on my phone if the procedure is not called more than 40 times. I chose an array size of 9x9 with 10 bombs in it. This means that in the biggest case, the procedure could be called 71 times... 

Is their a possibility to fix "undefined runtime" errors, that occure, when the procedure ist called more than 40 times recursively? 
There is the possibility to ignore this error on your phone (I use samsung galaxy s3 mini) and continue your game like nothing had happened, but it would be fine, if you could avoid that error.

I attached my code, the problematic procedure is called "fuellen", but I think, it is a problem with the recursive call, not with the code itself.

MyApp_short.aia



I notice in your recursive procedure you have not created any local variables,
specifically the number of neighbors.  Doing recursion using only global variables
is very tricky.

Please add comments to your code explaining how you keep a two dimensional
board in a list - is it a list of lists, or a simple list wrapping thru each row by row?

Your neighbor counting technique can't be explained .



I took some more time to read your blocks.
You are using lists of lists to store your board.

I suggest you avoid recursion by adding a heat propagation metaphor
to your loop.
Use the background color of each cell or use the contents of a hidden board
 to indicate if it is hot, warm, or cold.

When you get a cell touch, start all cells as cold.
If the cell touched is empty, set it to warm.
Then start cycles of heat propagation to neighboring empty cells.
In each cycle, for each warm cell, 
    set each neighboring empty cold cell to warm then
    set that previously warm cell to hot,
    counting how many cells got warm in each cycle.
    Stop cycling if no cells got warm.

This propagation technique can be used instead of recursion
to propagate zero cells from a touch.



Thanks for your answer.
This sounds like a good possibility, but in which order would you do the cycling to get every cell catched?



The brute force heat propagation cycle method I discussed
can use a pair of nested 1 to 9 for loops to cover every cell in each cycle.

It's simple but inefficient.

There's an alternative way to do heat propagation using three lists,
named Cold, Warm, and Hot, containing cell addresses, 
representing cells using 6 digit numbers - 
(1000 * x) + y
where x and y are row or column numbers (1...9).
Each cell name would reside in just one list at a time,
and would be moved from list to list as its state changes.
I picked 1000 to make the numbers easy to read and decode
and to accommodate big boards.

This single-quantity (sparse) approach lets you take advantage of 
the more powerful list handling blocks (is in list, look up in pairs,
find index of in list)

For convenience and simplicity, you might consider writing
a return value routine NEIGHBORS that will accept a cell address and
return a list of its neighbor addresses.
Other likely small functions:
X(nnnnnn) = QUOTIENT(nnnnnn,1000)
Y(nnnnnn) = REMAINDER(nnnnnn, 1000)
CELL(i,j) = (1000*i) + j

By using little routines like this you can make your
code fit in screen shots, the most enduring way to 
save your code for eternity (if you can find cave walls for them.)


App Inventor Work not saving

One of my students continually gets this message regardless of the computer she is working on. Any work she does in lessons cannot be saved. Her code is extremely simple, so there shouldn't be a problem. She cannot save any of the work she does.
 
"The blocks area did not load properly. Changes to the blocks for screen 520817906443874_Screen1 will not be saved."
I have had a look on the other forums but there doesn't seem to be an answer.
Any advise would be welcome.




There's definitely corruption there.  Not sure what it is though.  I deleted ALL blocks, and ALL media, and still get errors.

I'll pass this message on to the dev team, and maybe they'll have insights into what happened... But, as you said, it's a VERY simple project, and can be recreated in a few minutes, which is what I'd do... Open the project up and print the screen so you have the blocks.  Then, start a whole new project, and recreate it.

My guess is that something happened on day on a save... some corruption or a glitch of some sort.

Alternatively, you could load the project from a previous AIA file and build it back up.



The Project is corrupted.   I recommend saving the images, if the student does not have the originals.  Make a screen capture of the Designer and Blocks screen, so the student can see what the project is supposed to look like; then starting the Project from scratch with a new name.

Something happened.  What?

Here are some issues:   The student uses a Canvas that is about 325 x 225? or so.  The Numeric sprites all are 225 x 225.  That means AI2 has to shrink all of them to the small size seen in the campus image.  This shrinking should be done in a image program on the pc...shrinking these graphics to 25=25 or so.    The corruption might have occurred because of ten srites being shrunk.

The images in the student's Media folder... one is  a 1600 x 1127 image at 2.18 Mb ...VERY large and not yet used in the app.  The main image used on the Canvas uses only a small portion of these images...cropping should occur outside AI2.

What is responsible for the corruption?   I doubt any one of the above, but in combination they might have caused an issue.

Someone else might have another opinion.    I deleted images, one by one, blocks etc and got to the bare screen...something was still corrupted.  Start with a clean slate, use smaller images and things will probably be ok.   Also make a copy of your project periodically as an aia   and/or   Projects > Save project as.... giving it another name.    Unfortunately, AI2 does not have an un-do function.   If the student had a back up point, he/she could recover.

I strongly recommend the student start over John...painful...and he/she should reduce the size of the images to something compatible with an Android screen.

The student renamed most of the controls.   Many believe developers should rename the controls, I have been programming for over 30 years and I do not believe in it because renaming controls can cause corruption, is unnecessary .    If that is what you expect your students to do, then continue.


run-emulator


https://code.google.com/p/app-inventor-for-android/issues/detail?id=2579 using the following batch file,I was able to open the emulator, but was unable to connect with app inventor. it loops down saying that is connecting to app inventor. I have also posted the link from which i have downloaded the file.

--

Why are you running a batch file to open the emulator?    On a normal AI2 install, you do not have to run a batch file.


The instructions for running and installing the standard AI2 Google emulator are here: http://appinventor.mit.edu/explore/ai2/setup-emulator.html  
and specifically for Windows  http://appinventor.mit.edu/explore/ai2/windows.html  

The emulator should install with no issues on your Windows 8 PC.

--
As stated in the comments of the issue you point to, the scripts will look for a particular hardcoded path, which is what the majority of our users will have. If you have a custom windows install, things might not work. You can have a look at the scripts and see if you can figure out what's going on; they are at: https://github.com/mit-cml/appinventor-sources/tree/master/appinventor/misc/emulator-support

--
Firstly:  While downloading the appinventor setup, the command to run the emulator is a batch file.
Secondly:While clicking the connect menu in the editor,the emulator opens, but it doesn't connect to app inventor.
Please Reconsider.

--
Does the emulator screen show 5554 in the upper left screen?   That is the emulator that comes with App Inventor.   If you have perhaps 5556, you have a different version of the emulator perhaps installed with  a different program.  AI2 currently is looking to connect to 5554.   Perhaps that is part of the issue.

--

I have emulator 5554

--
I am not certain you attempted to set up the emulator correctly.  The correct emulator is appearing on your system.

The setup for a Windows PC is here:   http://appinventor.mit.edu/explore/ai2/setup-emulator.html   

In step 1, those instructions direct you here   http://appinventor.mit.edu/explore/ai2/windows.html  

Did you use the file  AppInventor_Setup_Installer_v_2_2.exe   ?

I suggest you uninstall the software, then reinstall to the default directory on your PC.   On a Windows 7 PC the files are here:

and should probably be in the same place on a Windows 8 PC.  Use the uninstall.exe , then immediately close your browser and reboot the PC before reinstalling.

--
Nothing Happens.

--
I re-installed the software. But I have the same error.

--
Can you tell me exactly where your files are being installed to, what is the install directory for your files?

--
We are experiencing some problems with running the emulator.  For some students it is working fine and when you launch the emulator they can see their app.  Other students start working but then when they try and run the emulator again are getting errors like "Launch the ai starter on your programme on your computer and try again".  They have previously launched it and used it successfully so I don't think it is an installation problem. All students are using the same network, same firewall and were installed the same way.  They have reset connection, closed and reopened app inventor and aistarter and some have rebooted their computers.  This is really frustrating and not giving a good impression of the software.  If it is installation surely everyone would have the same problem? I remember last year this being a little random but not this bad.  I REALLY don't want them using TouchDevelop but many of my students are wanting to review App Inventor.  HELP!

--
First I know how frustrating this must be for you, and would really like to get to the bottom of this issue. First could you check whether you are running the latest version of the setup tools. You can check by visiting the MIT App Inventor 2 Connection Test page here: 


It should give you a screen similar to this. Please let me know if the aiStarter is version 2.2

MIT App Inventor 2 Connection Test
Is aiStarter running?
YES, aiStarter v2.2 running!
Is your phone connected via USB?
NO, your phone is not connected via USB! Get USB Connection Help

--
The student that experienced problems with the emulator today ran this test and it showed that the starter was not running (even though it is on their desktop and in the startup menu)

--
Some emulator issues have been traced to poor coding using blocks, and on one occasion it appeared the PC a person was using was having hard drive and memory issues, causing emulator failure and ability to compile.  When these problems occur, does it always seem to be the SAME computer? You are using Win 8...that implies all the computers are relatively new?    Or are these older PCs with Win8 installed?

One instructor had similar issues to what you describe.  The problem was some students having sever coding issues.  When the block code is malformed or when one uses lots of layouts, this can cause problems.    Is this your issue?    Possible.  Only way to tell is to run a simple project on the offending computer.   Create a new Project.   Put a button on the Designer screen.  Now run the project in the emulator.  All you should see if it is running correctly is the emulator start, then the button render in the emulator screen.  Does the simple project work or fail.   If it works, look for a problem with the student's Project.   If it fails...well, something more serious..perhaps hardware issues.

Another instructor traced similar issues to the ability of the school network to handle 30 students simultaneously.  An upgrade of the Internet seemed to solve his issue.   Is this your issue?   No clue.

Here is my standard "What could be wrong?"   These things may not apply in your case, but some of these issue do cause issues running the emulator (even though they might mention compiling apk's and creating aia's, they still might be responsible for emulator issues).  Good luck.

One of the following  possibly applies to your code (all may not apply to your code):

1)  You have coding errors in your blocks.  In the Blocks editor, look in the lower 
left corner of the window for the yellow and red triangle icons. If the red icon has a value larger than 0, 
you have a serious coding error.  Find the block in your code that has a red triangle and 
fix it.   Red triangles always inhibit creating an apk or running a project in the 
emulator or possibly creating an aia file.     Yellow triangles are more forgiving, 
however, sometimes, these need to be fixed because they trip an internal warning and not billing puzzle piece sockets are left un-filled.

2) Your source file (the aia file) is larger than the 5Mb limit allowed in AI2 (the aia can not be larger than 5Mb). You may have put images or other resources in your Media (resources) that you do not use in the app. 
 All the images and sounds in resources count toward the 5Mb limit along with the souce code.    You can program 
apps larger than 5Mb in the browser, but the apps will not compile and might not run in the 
emulator or the project may not save as an aia. If this is the case you need to reduce 
the size of your image and/or sound files.   Most image files can be made quite small 
by resizing them using a photo manipulation program on your PC to less than 50Kb each.

3)  You might have more than 10 Screens in your app.  AI2 becomes unstable when more 
than ten screens are used.  Projects CAN be built with slightly more screen but then you should expect your app to occassionally behave erratically.

4) You might have set a Screen icon in the Designer Properties for your project that is too large. Use an image 
sizeof 48x48 px or 96x96px instead and only use jpg or png images.  *.ico files are not 
supported.  The 'icon' (actually an image) can be as large as 520x520 (I think that is the size GooglePlay apps require).  The smaller 'icons' work fine otherwise.

5) You did not code the entire project using App Inventor 2.   If you used one of the 
third-party AI2 clones,you might not be able to load a Project into the AI2 compiler or 
create an apk with the standard AI2.

6) If you incorrectly modified the project's Manifest files using a third-party tool, you may have issues.

7)  Sometimes, if you have LOTS of Layouts on a single screen,  the apk might not 
compile. How many is a lot?  I do not know, keep adding layouts and buttons, compile and try again...when the server crashes, you got a lot.

8)  The network you are using may be overloaded (possibly a school network), or you have other applications running in the background on your computer, or your virus checker is doing a scan.  Sometimes, just trying to access the MIT server a few minutes later will give you a more favorable response.

9)  If you have BlueStacks on your home PC (BlueStacks is a special emulator that allows Android apps to run on a PC).  The Google emulator on AI2 cannot run unless BlueStacks is disabled and all of the BlueStacks processes are shut down.  On a Windows PC, you use the Task Manager to 'kill' running processes.

10)  Are you using Sensor controls (except for the clock)?   Most Sensor controls or controls related to sms or the phone do not work in the emulators.  They need to be tested on a device.

11) If this is an issue about the Project loading slowly on your device or on the emulator:  Be aware, the more images, layouts, components you have on a screen, the longer it takes for the emulator and Companion to render the graphical screen.  How fast the emulator renders is partially a function of your hardware...how much ram you have, your cpu clock speed etc. Sometimes, with lots of graphics, the emulator will just give up.   Can you develop live using WIFI or using USB? These options almost always render faster than the emulator but will not be at lightning speed if you have lots of graphics.  Be patient.

12)  This happens too:   We have see instances where it is probable the Google Cloud messed up; other instances where an older PC has had memory issues and caused file corruption of the Project and instances where a user is using a very slow Internet connection (like dial-up) and it is just too slow.

13)  Do you have an AVG, Eset or AVAST virus checker.  Some versions of these products have been reported inhibit running the emulator unless (in the case of AVG) the Advanced Link settings on the software are set to allow AI2 communication.

The problem could be something else, like running an old version of Companion ...in this instance the cure might be:   Projects > Hard Reset.  If there are Companion issues a pop up will appear (if no issues, nothing will happen...just smile).  When the pop up appears, follow the instructions very carefully, then reboot your PC and try again.

--

Lists Help

Right now, I've got it where it's comparing the users input to items in a list. How do I make it to goes through the list and remove that item from the list? I think I'm getting the code mixed up. Thanks



don't hesitate to look at the fantastic tutorial yourself...

http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#inlist

is in list?


If thing is one of the elements of the list, returns true; otherwise, returns false. Note that if a list contains sublists,
the members of the sublists are not themselves members of the list. For example, the members of the list (1 2 (3 4)) are 1, 2, and the list (3 4); 3 and 4 are not themselves members of the list.
http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#indexinlist

index in list



Returns the position of the thing in the list. If not in the list, returns 0.


New to Google play

I have few question i hope you guys can answer all of them.
I have just created an app using app inventor and i have the .apk file and successfully installed on to my samsung s4.
Now i want to take a step further to upload to google play.

1. I did some research and i realize that when installing app inventor .apk file i have to check allow other apps to install other than google play. Can i use the app inventor .apk file to send to google play?

2. There is a signature when you use eclipse program but app inventor does not have how do i obtain the signature?

3. After paying the US25 and my app is been selling on the google play how many % will i get and how does google pay me for my earning?

4. I set my app inventor to the lowest version is it ok? which means most of the phone can run my application? What are the difference between high versions and low version.

4. Last question is there anything that i left out before paying and start uploading.




Let's start off by saying that App Inventor is in no way connected to Google Play, other than it creates apps you can distribute there.

1.  Yes
2.  Part of the development environment.  You don't need to do anything.
3.  That's all up to Google... They take a percentage and it's between you and Google.
4.  2.3 is the lowest version, but that will probably go up soon to 3.
5.  Go for it... Just make sure your app works, and isn't malicious.




let me correct answer 4: currently it's Android 1.5 (Cupcake) and after the tablet version release it will be Android 1.6 (Donut)

it seems to be, the version you are talking about is the version of your app, which should start with Version 1, see screenshot
you do not have to worry about the Android versions



I have tried published my app call 'Back To The Basics'. the version is  1. And now is already pass one day it still not in google play.
what can i do now. Is there anything i missing out?



just check again, this can take a few hours...


get other from list

Hi there, Is there a way to have 'get other' = 'any of the items in a list'?

I have a 'when collided.with' block that has many 'if then' blocks. Each 'if' contains a different 'get other' item but all of the 'then' actions are the same. So I'm wondering if I can put all of the items into a list so I would only need one 'if then' block to act on 'any of the items in the list'.



Have you tried using pick a random item list   block?



So I'm wondering if I can put all of the items into a list so I would only need one 'if then' block to act on 'any of the items in the list'.
yes you can
what kind of items do you have? image sprites? if yes, just create a list and put the image sprite components inside, then use the pick a random item as SteveJG said


Image File Format Requirements - Canvas Background for Color Picker

Is there a picture file size or format requirement that I'm not aware of? I've been looking all over this forum for over an hour now and and can't find a solution to this problem.

I'm trying to create a color picker based on a canvas background (as was recommended in another post here https://groups.google.com/d/msg/mitappinventortest/e34CCC1FLjk/oE4oGAZT3hEJ) and none of the palette images I set as the canvas background show up on thedevice screen...

1. Capture.png - Which came from the post I mentioned above.
2. ColorPalette.png - Also tried this file as a *.jpg, at 75% and 50% of the original size.
3. ColorPalette.bmp - Same thing, exported as a bit map.

The three files above do not render when I try to display them asimages.
The three files above do not render when I try to display them asscreen backgrounds.

However when I select something inappropriate from another project (BeerButton.jpg) as the canvas background it DOES render on the device.

Screen background color is "none".
Canvas background color is "none".

I imagine I'm missing some tiny little detail but I cannot for the life of me figure out what it is. I've even gone as far as to programmatically set the height, width, and visibility of the canvas... no change. 

 





have you tried setting canvas width and height arguments to a set number of pixels.  If the image is the background on the canvas then it should stretch and compress with canvas.  As far as I know there are no limits on image types and sizes but I know png and jpg work.  Also a know glitch is where it you don't connect using the qr code then images may not transfer.  It has not happened to me but some people in my class have experienced it.



Thank you for the advice, good thinking! I checked and this image is 593H x 295W. I've set the height and width of the canvas accordingly and still no change.

It's 94dpi, 32 bit. Maybe it's too much detail to be rendered? I might try converting it to 24 bit and see what happens.



it works fine for me, tested the first image on Nexus 5, see attached project
do you test with the emulator?




I'm using a Samsung Galaxy S4.

I loaded your *.aia file and it worked correctly, I then loaded my project and it miraculously works without my changing anything at all.

I really dislike problems that solve themselves. Without knowing the cause I can't guarantee it won't happen again.  

I will verify that all the attributes you have set for the canvas in your project are set similarly in mine. Thank you all for your help.


App works via companion but crashes when downloaded to device


I seem to have issues with apps running via companion but not after downloading. In my case (please keep in mind I am a neophyte working with app inventor) I took an app authored by a fellow Arduino enthusiast (with permission) and modified it to my needs. The purpose of the app is to control an Arduino controller via Bluetooth. The app is fairly simple; used to attach to a Bluetooth interface to control devices attached to an Arduino mc. The app was originally written using app inventor classic. After having problems I went back to classic and made the mods I needed and it ran fine via  the classic companion to my LG Lucid2. I downloaded both to my PC and directly to the phone and installed the app; it ran perfectly. Satisfied with my first project success, I felt I should do it with AppInventor 2 in the event classic was taken down. I edited in the block editor the same functions, and again they ran fine to the LG Lucid2 via the companion. But this time after downloading to the PC, (not seeing a way to download direct to the phone), then installing it, the app crashed at a point where a Bluetooth selection was to be made from "listpicker".. Reiterating that when written with the block editor in AppInventor classic, and downloaded it works. I still have that version on the phone. The app also works using AI2 Companion to the phone. It however does not work when downloaded and installed on the phone.

--
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.


--

Thank you for the timely reply Taifun, as stated block editing is very new to me, so I am at the start of the learning curve. That being said, the app is pretty basic and quite short, so I captured the entire block edit to give you a start to finish concept. I did add some additional things in AI classic but this is the basis of the issue. Again thanks for help and inspiration..

--
see here
how to connect correctly

--
I for sure appreciate any help, it will take me a while to digest this, since 1. as stated working with app inventor is new to me. (as well as bluetooth)  Since I "inherited" the portion of the app that connected with  HC -5 bluetooth module from the original author I assumed it was in correct form. (and it did work)  2. I don't understand why it works using both App Inventor classic, and AI2 using the associated companion, but does not work when downloaded after writing with AI2 block editor. I was hoping for not only a resolution to the issue, but an answer to that question as well.

--
Taifun, no offence but I don't think we're on the same page. My goal is to connect one way to a bluetooth module that will interface with an arduino controller. This has been done many times by many people using App Inventor classic. It Does work! There is also a very similar app on the tutorials at http://www.appinventor.org/bookChapters/chapter12.pdf that uses a very similar approach. What you presented to me seems to be way more than required to achieve the goal at hand with tons of overhead.

--
see also this thread https://groups.google.com/d/msg/programming-with-app-inventor/r9t9UWsxZ6k/iS6XBeAjgD0J
probably there is still a bug in App Inventor 2 concerning the evaluate but ignore result block? Why not just connecting correctly?

This is the correct method to connect to a Bluetooth device:
if BluetoothClient.Connect ...
then ... <successful connect>
else ... <error>

see also the documentation http://ai2.appinventor.mit.edu/reference/components/connectivity.html#BluetoothClient

boolean Connect(text address)

Connect to the Bluetooth device with the specified address and the Serial Port Profile (SPP). Returns true if the connection was successful.

Please prepare an example aia file as simple as possible which shows this issue. This would help MIT to fix it. Thank you.


Btw: which error message exactly do you get?

--
Most users here do not have arduino devices.  What others in the forum asked and how some of the solved issues is here:  https://groups.google.com/forum/#!searchin/mitappinventortest/arduino    It appears no one with a device or experience is around to test your code.


You could search in the forum using the Search for topics box to the right of the colorful google at the top of this page  using terms like arduino  or bluetooth     or search for app inventor arduino or bluetooth  on the Web and found other links.


Have you used the DoIt debugging tool to help yourself?  You can read about self debugging here: http://www.appinventor.org/bookChapters/chapter15.pdf 

I do not know why you app fails.   I hope you can figure it out with the suggestions above.   Perhaps Taifun's suggestion would work?  Otherwise, you are going to have to find a solution by experimenting; trial and error.

Best luck.   When you find a solution, please return and explain to us what the issue might have been.

--
Thanks for the response. Again I must reiterate that the procedure  built on has been around and used for quite some time. Even the tutorial I sent a link to doesn't go to the lengths of the example presented by "a simple bluetooth chat. IMHO that seems like a lot of overkill.  This is not a 2way "chat".The object here is to simply connect to the arduino via a bluetooth module, and sent a 1 byte instruction; the issue is not arduino:, arduino is simply the receiver of a byte then makes a decision of what to do in accordance with that byte. In this case: if byte =0 send a 1 second "high" pulse to gio pin X; if byte=1 toggle gio pin y. Again I must reiterate it works using App Inventor Classic. (where the original code was built ). Last night I went back into classic and added a proper app shutdown statement, and again it worked perfectly, linked with companion, and downloaded to the phone. Forgive me if I sound argumentative, I'm not trying to be, just trying to get the point across that there is a difference between AI classic, and AI2. The app works well written in classic, so I guess  I will continue using it, until it's either taken down or I begin to understand why so many apps have been written, and function using this method. Again thanks for your help.

--
Thanks for that Taifun, I will work to incorporate that into the blocks edit and see how it goes. Connecting "correctly" seems to be a subjective term. I will however follow your lead/advice to see if it makes a difference, using the if statement test. (again thanks for that). This situation calls for a 1 way 1 byte communication to a device that offers no response. Not a "chat". As stated many are using it (or were in App Inventor classic) (and it works). Again It works on AI2 when connected to the phone via companion. (it is the packaged, installed apk that doesn't work). I don't get an error code, as I originally stated, the app simply stops at the point the bluetooth device is selected in listpicker and returns to the screen prior to launching the app. The screen capture I attached previously indicates where this appears to be happening. I don't think I have downloaded .aia for the app in question in AI2, (I will do that and place it in my next post) and not sure if I have a similar project downloaded from AI CLASSIC ( I realize their format is different). Would you care to see that as well?

 Last night I went into "classic" and added a proper app shutdown statement, successfully tested via companion, and packaged and downloaded to the phone and all worked well.

--
"This is the correct method to connect to a Bluetooth device:
if BluetoothClient.Connect ...
then ... <successful connect>



See insert :
else ... <error>"

Lloyds_Garage_Manager_bigllodA12.aia

--
After much searching, I found this :

"This is the problem with 'Evaluate but Ignore result'
MIT is aware of this and have put in a fix and should be in the next release.

--