2017년 4월 10일 월요일

search for Problem getting the images of AI2 app displayed on Android


Make sure the background color of the screen is set to "none"...
Most of your images are 572 x 779 pixel images and all are displayed at reduced size. ... AI2 is getting a heart attack of processing of scaling. ... AI2 is a learning tool; not a commercial app creation tool; so any user has got to deal with the problems associated with MIT using creative solutions to simulate ...


Something really strange...


I have made a program that is working fine. It 3 screens and the second screen contains 24 images (the letters of the greek alphabet). The third screen just has a canvas. Each of the image is not bigger than 10kb. Also the size of the .aia file is only 274 kb.
When i run it in emulator or in the tablet with only 10 letters (not using images for the others) as i told is working fine. When i compile it (size 1724 kb) the program starts normally. But after trying to go to the second screen it crashes.
I upload the apk and the aia in case you have any idea to help me...

Thank you very much!

The apk file was removed by the moderators as a security issue.  Apk files are not permitted on the forum.  Thank you for the aia Stamatis ..someone will probably use it to provide advice.


--
This thing looks familiar to me from an earlier thread.
I think that something funny is going on because I got a runtime error like this:
Failed to allocate a 1697272 byte allocation with 158932 free bytes and 155KB until OOM
Note: You will not see another error reported for 5 seconds.

However, I totally fail to understand what you are tring to achieve in your app. Maybe you should start with less functionality and continue only when you have that working to satisfaction.

-- 
I'm looking into your problem. Try "Responsive" mode for the "Sizing" property on Screen1. Let me know if things work better, as in they don't crash, when you use Responsive mode. Thanks.

--
Smart people (like Jeff) are still looking at your problem, it may involve a memory leak. Stay tuned.
In the meantime, it could help to make your images smaller again, because they seem to be still way

--
The issue most probably is not the image file size but the size in pixels. Most of your images are 572 x 779 pixel images and all are displayed at reduced size. 
You are stuffing the 572x779 images in spaces that are 15% H and 22% width on screen 2 ...there are 24 like this...  AI2 is getting a heart attack of processing of scaling.  
The images are four across ,so this could work on a  572 x 4 = 2288 pixel wide x  6 x 779 = 4674 high tablet  ... and that is for only 80% of the screen.  Wow. Is there such a Tablet?

AI2 has a scaling issue with stuffing this many images into 24 images in one fell swoop.  This is not new, we have been counselling users not to stuff large pixel x pixel files into small buttons, telling them to right size the original in the media...then their apps work. When you use a percentage of the screen's height and idth you are stuffing large pixel x pixel images into a smaller space.  When Android developers use Android Studio or other professional compilers, the developers provide multiple copies of the images they use for different screen densities.  In the AI2 compiler, to allow novice programmers a lot of flexibility, MIT chose to use scaling of images as a simpler solution.     At the moment, their algorithm is not right and the only work around is probably to use same size images.
Are you a Java user?   You might be able to fix this, however, AI2 users either use use exact size pixels x pixels or put up with memory or other issues.  MIT is aware of the problem.  This is no quick fix.

I expect, but do not know, that when you use the larger images, internally in the AI2 compiled code, your png or jpg images are converted to bmp format .  These images are significantly larger than the png images.  It appears once the bmps are created at full size internally, the image is not destroyed on use .. (this is speculation).  So, a lot of memory is used which may exceed the memory available to your app


If you use exact size images, you probably will not get that error, but we do not know.  Perhaps try rezizing the images you store in Media by 50%...that might let you proceed (or you might have to right size the images).

AI2 is a learning tool; not a commercial app creation tool; so any user has got to deal with the problems associated with MIT using creative solutions to simulate the performance of the professional compilers.  MIT is looking at this issue and may or may not be able to provide a solution in the near or even far term.

Be aware MIT warns users  Responsive is very experimental.  They are still attempting to allow Fixed to perform as in Version 144 and earlier; it does in most apps but does not work as hoped in some apps such as yours.  Because Google changed how Android works in about September, MIT can no longer provide the gimmick they used in earlier versions of AI2 (they simply magnified the screen to make it fit on Tablets) You now have Fixed and Responsive and everything is not perfect.

I would make my 'original' images smaller ... a real fix might be a long time coming .    Perhaps MIT will get lucky and find what the code that is possibly memory leaking soon.  To move ahead now, resize.

--
Thank you very much.
Finally it works.
When i reduced the size of the pixels by 75% everything was fine.

For another time thank you very much!!!!

--
I am happy it works now. 

--
Here is my analysis of the situation with the tafa_light application.

Yes, we have a memory leak. It only effects the Companion. We will fix it.

However the App itself uses many images, all of which are ten plus times the size they should be. The “Alphabet” of greek letters are each about 1-3 Megabytes in size. There are about 20 of them.

On most Android devices, the maximum size of Dalvik (the virtual machine that runs apps) memory is about 50 Megabytes. When displaying Screen2, the Alphabet, it just about completely fills memory when they are not scaled. Because of the memory leak, when you left Screen2, the memory was not cleared. The additional use of Screen3 (or going back to Screen1) would cause an out-of-memory error. Most applications do not recover from such an error.

Since the “Responsive” release [1] we have been automatically scaling images to compensate for each device’s screen density. On my One Plus One, the density factor is 1.3. This means that each images is increased in size by a factor of 1.7. When you add this additional memory, the Dalvik “heap” overflows and the application crashes. This is independent and not related to the memory leak. It just requires too much memory.

The solution is to resize the images. Most images appear to be 500x750 pixels (which is about the size of a typical phone’s entire screen). I suggest that you use an image editing tool to rescale them to 50x75 pixels. Then you shouldn’t have any significant memory issues. From reading the last message in this thread, it appears you have already done this and it now works.

[1] Prior to the Responsive release we set applications minSdk value to 3 (it is now 4). When set to 3, Android itself did the scaling and we didn’t have to. However with minSdk of 3, we cannot size applications to fit on tablets. Tablets wind up looking like big phones! We are also seeing newer devices that do not implement this compatibility scaling, so App Inventor was not working correctly on these devices. Going to a minSdk 4 means we can support these devices and tablets, but we have to do the scaling in our code.

--

507error is your device turned on? plz reply it depends on my graduation project


hello !! i have a problem in connection between my application and my bluetooth module which i use in arduino.. and also has a problem in connect two device via bluetooth in a conversation app via bluetooth i made with MIT App Inventor.. i use Mobile Sony Z2 with Android 5.0.2 and also tried on Samsung i Found the Same Problem .. "Error:com.google.appinventor.components.runtime.bluetoothClient@1b0d09a6,507,Connect,unable to connect . Is your device turned On ?

--
There is probably advice here https://groups.google.com/forum/#!searchin/mitappinventortest/arduino$20507

You probably have not 'paired' your devices or you have your bluetooth client on a different screen than the instructions you provide. When App Inventor switches screens, bluetooth connections unconnect so you should be using a single screen to program.  This is the way AI2 works, if you want to maintain a bluetooth connection, you cannot switch screens (if that is what you are doing).


--
 pair the bluetooth devices first


AddressesAndNames
The addresses and names of paired Bluetooth devices

--
What Bluetooth hardware are you using? Many embedded modules are finniky to connect to Android phones. You might just need to try connecting a few times or reorienting the module - the relative orientations of the aerials can be an issue.

It would also help if you post the bluetooth-related blocks so we can tell what you might or might not be doing wrong.

--

Bluetooth .connect block unreliable.


Hello and thanks in advance for any help I might get. 

I am writing an AI2 app that uses bluetooth comm to control and Atmel328 MCU via an bluetooth HC-06 module and an android tablet.  For app development I'm using Ubuntu 14.04 and Chrome browser.   My app has multiple screens.  I have read that a bluetooth connection is not maintained when switching screens.  Therefore, I am disconnecting prior to switching to a new screen, and then reconnecting as needed on the new screen.  This seems to work  for the first .connect instance on the new screen, however ALL subsequent connection attempts spawn the dreaded 507 error 'unable to connect'.  Cycling power on the BT module is the only way to recover original functionality.  I have tried this using different  HC-06 modules and android devices, both with the stand-alone apk file and from within the AI2 web development environment.  The results are always the same.. breaks/hangs the BT module on disconnect in the second screen   It seems to me that the bluetooth is not disconnecting properly, although the HC-06's LED blinks to indicate the lost connection.   My questions are; 

1.>  Is it possible to run from bluetooth from multiple screens as long as you disconnect-change screen-reconnect?
2.>  Is there some  minimum wait time between the sending/recieving data, disconnecting a device, changing screens (is it a timeing issue). My data never exceeds 16 bytes at 9600 baud?    
3.>  What Bluetooth device seems to be the the most problem free with respect to arduino comm?

I'm at a loss as to how I can run this problem down and would appreciate any assistance.

--
This seems to be a common problem with embedded Bluetooth modules. I see similar with the Microchip RN42. Are you able to change any settings on the HC-06? I've never used it but from what I've seen it seems to be a very basic unit.

On the RN42 I find that increasing the page scan and inquiry windows helps but even still the unit is not receptive to quick disconnect-reconnect cycles. I've read that this is something to do with how Android implements Bluetooth although I do occasionally get the same problem when connecting via Windows.

I've not tried it myself but I've read elsewhere that others have had some success with hiding parts of the screen rather than switching screens but how well that would work depends on your app.

--
Good to know that I'm not totally clueless.  
I have not tried to change HC-06 settings.  The HC-06 was provided with the default app-style documentation, NONE!  However there are a few user references our there.  I'll give it a go.  
Realizing that the HC-06 is, as you say, a "basic unit", I'm interested in hearing from anyone with better alternative device experience i.e Sparkfun's BlueSMiRF.  Five times the cost - five times better?
You mention increasing the "page scan".  What does that mean and how is it accomplished?  Also "quick" disconnect-reconnect cycles is relative.  What wait duration do you recommend?

--
Google the Microchip RN42 module. The documentation on that is extensive and explains the various page and inquiry scan settings - although they are ones that apply to that module. You'd have to find equivalent commands - should they even exist - for the HC-06. Basically, the module doesn't spend all the time looking for something to connect to, it powers down for a period then wakes up again and scans for things trying to connect. All you do is increase the duration of this scan period.

Unfortunately the duration between cycles sometimes needs to be in minutes to work reliably! It seems to vary, some I can connect to no problem, others take several tries. I also find sometimes it helps to move either phone or module - these things have PCB antennas which are highly direction-sensitive. Moving to a module that uses a whip-type antenna would improve things a lot but also add to the cost.

As for other modules, aside from the occasional connection problem I'm have lots of success with the RN42. In particular it is good for distance - I've been able to communicate with a unit about 30m away through two walls without any problem. Documentation is great, the only problem you may have is finding it in a prototype-friendly form as it is most often sold as a surface-mountable module. I believe there is a version with SIL headers but it costs a lot more.

--
A bit more on the RN42:

You can get the RN42XVP-I/RM - this has pin headers so will be easier to prototype with. Depending on your country you may find a better supplier, as I'm UK based I generally prefer Farnell:
http://uk.farnell.com/microchip/rn42xvp-i-rm/module-bt-802-15-1-xv-cl2-pcb/dp/2321374

The Microchip RN42 page is:
http://www.microchip.com/wwwproducts/Devices.aspx?product=RN42

The command reference guide is the most detailed.

--

Posting Guidelines


MIT App Inventor Forum Posting Guidelines
This forum is lightly moderated, and we've created a few ground rules and best practices to make these forums a great place for discussion.
Tip: Read the Google Terms of Service in addition to this article to understand terms of participating in these forums.
The ground rules for participating in a Google Product forum are:
⦁ Create topics and posts related to the forum's subject (a specific MIT App Inventor question or comment).
⦁ Choose the most appropriate category for your topics. Using the appropriate category makes it easier for other forum visitors to find and contribute to your topic.
⦁ Create posts that are related to the question or discussion to which you are responding. Use search to find questions or discussions that are related to your interests. If you are unable to find a related topic, you may start a new one using the "Post a question" button. Multiple off-topic replies may lead to forum suspension.
⦁ Create clear and concise topic subjects and posts. Subjects should not be in all capital letters. Include only important URLs (posts with excessive URLs will be removed).
⦁ Do not include personal information. To ensure your safety, security, and privacy, never post your email address or any personal information you don’t want to share with the world. Be cautious if you choose to contact others offline or ask others to contact you.
Ground rules for content
Posting certain types of content might result in the removal of your topic or post. In more serious cases, the poster might be banned from the group or lose access to your Google Account. Posts must not contain the following types of content:
⦁ Spam. In these forums, we're all responsible for keeping the community spam-free. Spam includes, but is not limited to, any promotional, commercial, or adult content, multiple instances of the same post, posts with URLs unrelated to the question, and the transmission of malware, viruses, or anything that may disrupt service or harm others.
⦁ Nudity and sexually explicit material. We don't allow nudity or sexually explicit material. We also don't allow content that drives traffic to commercial pornography sites.
⦁ Violent or bullying behavior. We don't allow threatening, harassing, or bullying of other users. This includes using profanity to abuse others.
⦁ Hate speech. We don't allow the promotion of hatred toward groups of people based on their race or ethnic origin, religion, disability, gender, age, veteran status, or sexual orientation/gender identity.
⦁ Impersonation. We don't allow impersonation of others or other behavior that is misleading.
⦁ Private and confidential information. We don't allow unauthorized publishing of people's private and confidential information, such as credit card numbers, Social Security numbers, driver's and other license numbers, or any other information that is not publicly accessible.
⦁ Copyright. We will respond to clear notices of alleged copyright infringement. Please flag any copyright material as such by clicking the Report Abuse link and selecting the 'Copyright' option.
⦁ APK files.  Please do not post packaged applications (APK files) unless specifically requested by one of the moderators.  This forum is not designed to be a distribution channel or a review or advertizing channel for apps, whether free or paid.  To distribute your app, you can put it in Google Play or some other app market.  On the other hand, feel free to use the forum to tell people if you've created an interesting app, and link to the copy of the app in the market.
Our Agreement:
By participating in these forums, you agree to abide by these guidelines. Breaking these guidelines might result in your post being removed. Severe abuses may lead to harsher penalties. Please read the Google Terms of Service for further information. We reserve the right to change these guidelines at any point in our effort to keep the forum clean, user-friendly, and safe. If you believe that someone is violating these posting guidelines, use the Report Abuse link on the post. If you click Report Abuse, we'll try to promptly review your report and take action, if appropriate.
Let's work together to keep these forums a clean and friendly environment. Happy posting!

--

problem with bluetooth appplications


so i had trouble using two application i created (accept and final1), the application say ''unnable to connect , is the device turn on?''  .
in order to see if the problem was my applications i did download two applications i found on internet(BTclient and BTserver) but it still not work , so i don't understand 
could you help me i would really enjoy that ,if you want the files in aia
PS. sorry for my poor quality english

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

PS: I removed the apk files for you, see the Posting Guidelines.

--
sorry for the apk files , heres are the screen shot of the blocks that take care of the bluetooth then i did a test with the code from here http://appinventor.pevest.com/?p=520 and it did not work better . the little one is just a program to accept the connection (i don't know if i need it to make my fat program work ) the fat one is my program

--
1. how to connect correctly see screenshot
2. use procedures to avoid redundancy, see here http://twodogapps.com/?page_id=686#Procedures

3. you might want to try this example to see, if the connection works there
--
i am trying my programs with 2 phones with bluetooth on but the server say ''error 508 unable to listen for a connection from a bluetooth device'' and the client say ''error 507: unable to connect is the device turned on?
--
why repeating to accept the connection over and over again? do it only once in Screen.Initalize, see again https://puravidaapps.com/btchat.php
--
also make sure, that bluetooth is enabled on both devices...

BluetoothServer1.IsConnected or BluetoothClient1.IsConnected


actually a very easy issue but either I am too dumb to see the problem or I have an issue here
I want to work with an event when the mobile phone disconnects from the hands-free in the car.
I assume that when a hands-free is connected either bluetooth server or client of the phone is set to true and I can use the logic when true turns to false again.
But I have tried with three hands frees now and the isconnected stays always at false (the clock1 fires every three seconds and I have a beep included to assure that the when function really works).
Why does this not work or does anybody have another idea how I can detect when a bluetooth device is disconnected?
Thank you for your help :)9
--
the property IsConnected will unfortunately not be updated, after a device will be disconnected, which means you will get Error 516: Unable to write: Connection reset by peer", see also chapter "known issues" here https://puravidaapps.com/btchat.php, however you can catch that error in the Screen.ErrorOccurred event

--
thank you for your quick response.

But I checked your known issues and it says there
As far as I can see, after client or server disconnected, there is no possibility for the chat partner to see, that the connection is gone. Therefore currently an "Error 516: Unable to write: Connection reset by peer" will be diplayed after trying to send a text without connection
But I am not talking about the partner since in that case the parter would be the hands-free, wouldn't it?
The IsConnected is running on my own phone and when the hands-free is disconnected then the status has to change because if not it would stay forever at true. Or do I have to set it at false myself?

--
when the hands-free is disconnected then the status has to change because if not it would stay forever at true.
that's correct, as far as I remember correctly, it stays forever at true 

-- 
In my case it stays forever false ... grrrr

I try the idea  to catch an error

--
I am despairing.

I am using the command bluetoothclient1.Sendtext Text:a
to verify if there is a bluetooth device connected or not and although I have tried with three differed free-hands the error message shown on the device is:
Error 515: Not connected to a Bluetooth device
although the free-hands work and bluetooth shows in the mobile device the correct connection

--
are you sure, you have a successful connection?

This is the correct method to connect to a Bluetooth device:


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.

--
thank you for this tip.

Until now I never connected myself the Bluetooth connection manually with the programming language (like you propose) but I assumed that this happens already with Android automatically.

Does your proposal mean that I cannot rely that the phone itself (the operating system) establishes the connection and then the value of IsConnected is automatically True?

--
there is nothing automatic, you have to do the connection

-- 
sorry if I engage you so much into this discussion and I am very grateful.

But why can the application not assume that Android runs a bluetooth connection already when in reality it is an established connection to a hands-free?

When I request the physical position I also get it without activating GPS or other location methods. The location is stored in the locationsensor already.

You understand what I mean? My idea would be actually to check if under the normal Android operating system a bluetooth connection is already running and inform the app if it is disconnected. The app does not need a bluetooth connection. It is only required to know when a connection is lost.

--
 I don't have one of these gadgets.....then possibly user a timer to poll whether the connection exists continually and if the connection is no longer there  ....connection was NOT successful  becomes connections is LOST  ?           Does that work?

--
I implemented your proposal explicity in a separate project.

But the problem remains the same. Neiter via the web connect nor as an app installed on the phone it establishes a bluetooth connection with the hands-free when selected.

Failure message is: Error 507: Unable to connect. Is the device turned on?

BUT when I connect the phone WITHOUT the app directly to the hands-free via Bluetooth in Settings of the Samsung S3, it connects with no problems (just not via the app) and the hands-free works.

There must be something in the app which does not allow the bluetooth connection to be established ...

--
thank you and yes, that is possibly not possible with App Inventor.

Since I am not a programmer, App Inventor was the obvious choice for me.

My idea was to create an App which saves automatically the position of my car when the phone gets disconnected from the hands-free of the car.

Like this it is not necessary to press a save button opening the app beforehand etc. :)

--