首页资源分类应用技术射频与通信技术 > App Inventor 2 code snippets

App Inventor 2 code snippets

已有 445125个资源

下载专区

上传者其他资源

    文档信息举报收藏

    标    签:Android

    分    享:

    文档简介

    Android App design tool.

    文档预览

    App Inventor Code Snippets | Pura Vida Apps Page 1 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) (./index.php) App Inventor Code Snippets Payroll on AutoPilot™ All Your Calculations Are Automated Free Yourself From Outdated Payroll This page lists useful code snippets for (http://appinventor.mit.edu/). App Inventor 2 The snippets for App Inventor Classic you can now find here (./snippets1.php). These and more Examples you can find at the Tutorials (./tutorials.php) page App Inventor and dynamic table layout with any number of rows and columns (./table.php) How to display a table in App Inventor without knowing how many rows and columns will be supplied. (./table.php) What's New? ◾ How to sort a list using the webviewer(!) ◾ A workaround for the decimal separator problem ◾ How to get european or chinese characters from Web ResponseContent ◾ How to get the max value within a list of numbers ◾ How to start a Skype call ◾ How to enable Bluetooth (User still needs to confirm) ◾ How to start OsmAnd and open the map with a place marker ◾ How to copy text to the Clipboard ◾ How to start Whatsapp/send a message with Whatsapp ◾ How to execute statements in the Jackpal Terminal Emulator ◾ How to use the YandexTranslate component ◾ How to read a file stored as asset in App Inventor ◾ How to keep the screen on ◾ How to create a directory http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 2 of 31 App Inventor Code Snippets Overview Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) The snippets for Canvas App Inventor Classic you can now find here (./snippets1.php). ◾ How to save a canvas ◾ How to create a Scratchcard with App Inventor ◾ How to Swipe left/right and top/bottom to trigger something ◾ How to change background image without changing drawn lines Web Viewer and App Inventor ◾ How to read a HTML page stored as asset inside of App Inventor ◾ App Inventor and animated gifs ◾ How to view a pdf document ◾ How to pass user and password for basic HTTP Authentication in URL ◾ How does the new property Webviewer.WebViewString work? ◾ How to sort a list using the webviewer(!) ◾ How to get the max value within a list of numbers Activity Starter ◾ How to launch Google Play from within your app ◾ How to add a contact to the contact list ◾ How to send an eMail ◾ How to launch Waze to look for a specified location ◾ How to view a pdf document ◾ How to pick an image using the activity starter ◾ How to use Activity Starter to view a Youtube video in full screen ◾ How to start a Skype call ◾ How to enable Bluetooth (User still needs to confirm) ◾ How to start OsmAnd ◾ How to copy text to the Clipboard ◾ How to start Whatsapp/send a message with Whatsapp ◾ How to execute statements in the Jackpal Terminal Emulator Other Stuff ◾ App Inventor and the Screen Size ◾ How to build a simple compass app with App Inventor ◾ An enhancement to the compass app to provide additionally the direction to a waypoint ◾ How to trigger something if device is facing down ◾ How to create a nested listpicker ◾ How to get a date in format YYYY-MM-DD ◾ How to get leading zeros in App Inventor ◾ How to get the day of year ◾ How to parse a result ◾ How to use the Sound Recorder ◾ New formatting possibilities with the Notifier ◾ How to play a random sound when the device is shaken News (news.php) http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 3 of 31 ◾PuHraowVdidoaesAtphpeslo(oinkduepxi.npphapi)rs bloAcpkpsw(oaprkp?s.php) Snippets (snippets.php) ◾ How to pick a random item from a list without picking duplicates? Tutorials (tutorials.php) ◾ForHuomws (tfoortuamk.ephapp) icturLeinokrs p(licnksa.pnhpim) ageSaenardchsh(saeraercith.php) Contact (contact.php) ◾ A workaround for the decimal separator problem ◾ How to get european or chinese characters from Web ResponseContent ◾ How to use the YandexTranslate component ◾ How to read a file stored as asset in App Inventor ◾ How to keep the screen on ◾ How to create a directory News (news.php) Do you need help with your App Inventor project? I can help you: for one hour I charge 25 USD. Please contact me at info@puravidaapps.com (mailto:info@puravidaapps.com) for details! For questions about App Inventor, please use the App Inventor forum (https://groups.google.com/forum/#!forum/mitappinventortest). Thank you. Canvas How to save a canvas This is a small add on to the Paint Pot tutorial (http://www.appinventor.org/paintpot2-steps). Add additionally a Button and a TinyDB component. Then in the block editor add these two blocks. The function Canvas.Save and Canvas.SaveAs return the directory and filename. Therefore you have to define something (e.g. a variable or a label) which is able to receive this information. In the example this information is stored in a TinyDB, so the next time the app starts, the drawn picture is still there. In this example the image will be stored in the root directory of your SD card. Feel free to add a directory, for example /MyDirectory/MyCanvas.png Back to top of page ... How to create a Scratchcard with App Inventor It has been asked in the forum (https://groups.google.com/d/msg/programming-with-app-inventor/5IJFXiY1iWk/q7G9TXjcIE0J) how to create a scratchcard with App Inventor. This is my solution. http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 4 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://code.google.com/p/puravidaapps/downloads/detail?name=scratchcard.aia) Back to top of page ... How to Swipe left/right and top/bottom to trigger something It was asked in the forum (https://groups.google.com/d/topic/programming-with-app-inventor/7wQ1It4kw1M/discussion): I'm trying to swipe to change an image. How can I do that?. This is a nice example for the flung event. Let me add additionally another requirement (https://groups.google.com/d/msg/mitappinventortest/ZgWcquHeMPw/fGexI2FSJj4J): swipe to the left or right to change an image and swipe to the top or bottom to change the background color. We can use the heading property to find out, in which direction there was the swipe, the heading ranges between -180 to +180. http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 5 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/flung.aia) Back to top of page ... How to change background image without changing drawn lines http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 6 of 31 IaPtnuwraaapspVatishdkaaetdAwipinllptahslleo(winfdmoereuxmt.oph(tahpktt)epsa:/p/gAicrpotpuusrpe(saa.pgnpodso.ptghhleep)n.codmraS/wdn/iompnpsegitts./mT(sihntaeippnppeeitnxsvt.peshntpet)oprtweosTut/ulFdto8brAieaQlstto_(tItuChtoe4rnYiaobls/e.jp1ahGbp1)leMt1oQNvdieePwwsZg(tnhJee)w: dsI'r.mpahwcpnr)epaatirnt g without the background image. How would I do this? TFohreumosnl(yfopruomss.pibhpili)ty I cLainnksse(eliniksst.ophspe) t theSteaakrcehn(ismeaargche.pahsps) creeCnonbtaacckt g(croonutancdt,.pthhpe)n draw on the canvas. I set the Canvas background color to none in the Designer window to be able to see the background image. The Screen background color will be set to none after taking the first image in the Camera.AfterPicture event. Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/draw.aia) Back to top of page ... Webviewer and App Inventor From the Palette, expand 'User Interface' and add a 'WebViewer' component to the screen. How to read a HTML page stored as media file inside of App Inventor The example uses 2 html files and an image stored as media files inside of App Inventor. In case you like to take a look at the source of these files, upload the App Inventor aia file to App Inventor and download the html files from the assets list. There is one special thing to consider for HTML documents uploaded as assets into App Inventor: During development, you have to use the development path to the embedded HTML document. http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 7 of 31 file:///mnt/sdcard/AppInventor/assets/.html Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Before building the app, use the production path. Tutorials (tutorials.php) Forums (forum.php) Links (links.php) Search (search.php) file:///android_asset/.html Contact (contact.php) News (news.php) Note: External anchors are working only for Android 2.x devices but not for Android 3.x and 4.x devices. Thank you Ehsan for finding it out. Example: An external anchor is to go to the following url with a webviewer file://android_assets/page2.html#myAnchor. This works only for Android 2.x. You can go to this page file://android_assets/page2.html and inside the h4ml document jump to the anchor, this works for all Android versions. Download aia file for App Inventor 2 (https://code.google.com/p/puravidaapps/downloads/detail?name=HTML.aia) Download apk file (https://code.google.com/p/puravidaapps/downloads/detail?name=HTML.apk) Back to top of page ... App Inventor and animated gifs You can access an animated gif file directly with the webviewer component. There is one special thing to consider for HTML documents uploaded as assets into App Inventor: During development, you have to use the development path to the embedded HTML document. file:///mnt/sdcard/AppInventor/assets/ani.gif Before building the app, use the production path. file:///android_asset/ani.gif http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 8 of 31 PuDroawVnilodaadAapiapfsile(ifnodr eAxp.pphInpv)entorA2pp(hs t(tappsp:s//.cpohdp)e.gooSgnliep.pceotsm(/spn/ippuperatsv.pidhapa) pps/Tduotowrniallosa(dtust/odreiatlas.ipl?hnpa) me=Naenwi.sa(inae)ws.php) Download apk file (https://code.google.com/p/puravidaapps/downloads/detail?name=ani.apk) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Back to top of page ... How does the new property Webviewer.WebViewString work? As explained by Hal here (https://groups.google.com/d/msg/mitappinventortest/RCinmiNFgGc/2oTdj7dWTXoJ): You can use WebViewString to communicate values back and forth between your App and the WebViewer. In your App, you get and set the WebViewer.WebViewString properties. In you webviewer, you open to a page that has Javascript that references the window.AppInventor object, using its getWebViewString() and setWebViewString(text) methods. Thank you Hal and Jeff for this great enhancement! For the example, I uploaded a html page as asset into App Inventor. Alternatively of course you can use a directory on the SD card, e.g. file:///sdcard/Temp/stuff.html There is one special thing to consider for HTML documents uploaded as assets into App Inventor: During development, you have to use the development path to the embedded HTML document. file:///mnt/sdcard/AppInventor/assets/webviewstring.html Before building the app, use the production path. file:///android_asset/webviewstring.html HTML file Test Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/webviewstring.aia) Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 9 of 31 How to sort a list using the webviewer(!) Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) After Stephen provided his solution for How to sort a list of names (Fhotrtupms:s//(gfororuump.sp.hgpo)ogleL.cinokms/(dli/nmkss.gph/mp)itappSinevaercnhto(sreteasrct/hp.p2hEp-)r_jNECZon4t/aKc8t _(c_oPnItaKc9t.wphHps)J), I was thinking, why reinventing the wheel? Why not just using a simple JavaScript sort method (http://www.w3schools.com/jsref/jsref_sort.asp)? See the ridiculously simple solution below. This sort works with numeric and alphanumeric values. To perform a numeric sort, you must pass a function as an argument when calling the sort method, see the examples here how to do it (https://groups.google.com/d/msg/mitappinventortest/p2E-r_jNEZ4/K8__PIK9wHsJ). To reverse the sort order, just add .reverse() You also can sort list of lists using this method, see an example here (https://groups.google.com/d/msg/mitappinventortest/pVA3VUMN5W8/pZLttKYl3-8J). Note: The data limit using this method is around 2 MB (max. length of an URI) (http://stackoverflow.com/a/417184/1545993) For sorting more data, the data also could be passed to an embedded html file in the WebViewString property. Successfully tested on Nexus 5 running Android 4.4.3 and Samsung Galaxy Tab 10.1N running Android 3.2. For the Galaxy Tab the home url needs to be set first to get this runnning. Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/sort.aia) Back to top of page ... How to get the max value within a list of numbers It has been asked in the forum (https://groups.google.com/d/msg/mitappinventortest/EZVZjW4ZwWc/fiyiGHYrdzYJ): I was trying to calculate max value within a list of numbers. Can you make it without using a loop? ... I started with the same solution as spider pig showed, and that made me wondering if anything faster is possible. This is my embedded HTML/JavaScript solution, which is based on this stackoverflow answer http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 10 of 31 (Phuttrpa://VstiadcakoAvpeprfslo(win.cdoemx/.ap/6h1p0)2340A/p1p5s4(5a9p9p3s.)p.hTph) ankSynoipupentes w(ssnpipipreet!s.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/max.aia) Back to top of page ... Please also take a look at the App Inventor and embedded HTML/JavaScript tutorials and advanced examples (./tutorials.php#html) . How to pass user and password for basic HTTP Authentication in URL According to this info on serverfault.com (https://serverfault.com/questions/371907/can-you-pass-user-pass-for-http-basicauthentication-in-url-parameters) it is possible to pass user and password in a URL to be able to access a restricted area. The format to be used is http://username:password@example.com Unfortunately this does not work for all Android versions. I tested that on HTC Desire running Android 2.2 and Nexus 5 running Android 4.2.2 and it worked. It did not work on Samsung Galaxy Tab 10.1N running Android 3.2. An example how to download a file from a restricted area you can find here (https://puravidaapps.com/filedownload.php#restricted). http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 11 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Back to top of page ... Activity Starter How to launch Google Play from within your app Back to top of page ... How to add a contact to the contact list Provided by Fabio in this thread (https://groups.google.com/d/msg/programming-with-appinventor/UbFfTQJL4ls/JfCFpEScaj8J). Thank you! The default data type is "mobile", unfortunately we can't change that with MIT App Inventor, because we only have one ExtraKey - ExtraValue pair we can send with the Activity Starter. Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 12 of 31 How to send an eMail Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Following the Activity Starter documentation (http://ai2.appinventor.mit.edu/reference/other/activitystarter.html) we easily can sFoernudmasn(foerMuma.ipl hwpit)h theLiGnkms a(liinl kcsl.ipehnpt): Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://code.google.com/p/puravidaapps/downloads/detail?name=eMail.aia) Back to top of page ... You also might be interested in the example How to send an email with attachment (./sendmail.php) . How to launch Waze to look for a specified location Following the Waze documentation (https://www.waze.com/about/dev) we easily can open Waze and look for a specified location: Back to top of page ... How to view a pdf document You can use the Activity Starter to view a pdf document, which is already stored on your device. How to download files from the internet to your device. (./filebyfile.php) To open a pdf document from the Internet, I used a webviewer together with the Google Docs Viewer (https://docs.google.com/viewer) and the link to the pdf document. It has been asked in the App Inventor forum (https://groups.google.com/d/topic/programming-with-appinventor/WY3yzeDv1us/discussion): I have uploaded the PDF files into the media section in App Inventor but I just can't seem to find how to make them open from clicking the button. Note: It is not possible to store a pdf document as asset in App Inventor and view it with a pdf viewer. This is, because App Inventor itself can't display pdf files and external pdf viewers called with the activity starter from App Inventor are not able to access assets inside the app. http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 13 of 31 YPouuraalVsoidma iAghptpbse (iinntedreexs.tepdhpin) the following example: Apps (apps.php) How to pick a file from Snippets (snippets.php) SD card with App Inventor (./pick.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/pdf.aia) Back to top of page ... How to pick an image using the Activity Starter The Image Picker component is limited to 10 images you can pick from (https://groups.google.com/d/msg/programming-withapp-inventor/vvBgZo6uFuU/jR8ckuMnF28J): When the user taps an image picker, the device's image gallery appears, and the user can choose an image. After an image is picked, it is saved on the SD card and the ImageFile property will be the name of the file where the image is stored. In order to not fill up storage, a maximum of 10 images will be stored. Picking more images will delete previous images, in order from oldest to newest. Alternatively you can use the Activity Starter without such restrictions. Thank you Jari for this tip (https://groups.google.com/d/msg/programming-with-app-inventor/hV9Io1Iroo8/xbhQzcEa8SkJ). http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 14 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/imagepicker.aia) Back to top of page ... How to use Activity Starter to view a Youtube video in full screen In the Designer set Screen.Orientation to Landscape. Thank you Aaron for this example (https://groups.google.com/d/msg/mitappinventortest/rO0Lxqxn0nQ/Qel7ZMAiQDoJ). Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/youtube.aia) Back to top of page ... How to start a Skype call http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 15 of 31 T(Phhutitrspa:A//VsptipadcIankvoAevpneptrofslros(wion.lcudoteimoxn/.qpi/s1h8bp5a)8s6e4d1Ao1pn/p1ts5h(4ias5p9p9ss.3pta)h.cpTk) hovaenrSkflnoyiwpopuqetuasel(lssentmiiopnapteattisno.dp!hapn) sweTr utorials (tutorials.php) In the textbox you can enter a Skype name or a phone number. Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) News (news.php) Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/skype.aia) Back to top of page ... How to enable Bluetooth (User still needs to confirm) Solution found here: App Inventor Activity Starter App (https://play.google.com/store/apps/details? id=appinventor.ai_mletsch80.AppInvActivityStarter). Thank you mletsch! Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/enableBT.aia) Back to top of page ... How to start OsmAnd and open the map with a place marker As it has been said in the Activity Starter documentation (http://ai2.appinventor.mit.edu/reference/other/activitystarter.html): If you can find the "cmp=" string, then the ActivityPackage is the part before the slash, and the ActivityClass is is the entire "cmp=" part, without the slash character. To find the correct DataURI parameter to use for OsmAnd, see the OsmAnd documentation http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 16 of 31 (NPhuotttrpeas::VF//ciodoradOeAs.gmpopAosngdl(e+i.ncpdoleemax/sp.pe/ohuspsm)eannedt/Aw.opispksim/F(aaApnQpds#..ppWhluphs)ati_nisntSteenanipdtspo_eftdsno(eesnts.i_opOpsemstmsa.pnAhdnpd)a_slisAtcTetunivt_oittryoia?lPs)a.(tcuktoargiael.s.Tphhpa)nk yoNeuwHsa(nreryw!s.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/osmand.aia) Back to top of page ... How to copy text to the Clipboard Precondition for this solution to work: the Google Docs app is installed on the device! Solution found here: App Inventor Activity Starter App (https://play.google.com/store/apps/details? id=appinventor.ai_mletsch80.AppInvActivityStarter). Thank you mletsch! Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/clipboard.aia) Back to top of page ... How to start Whatsapp/send a message with Whatsapp How to send a Whatsapp message to a specific mobile number? There is this Android solution (http://stackoverflow.com/a/17800182/1545993) but this is unfortunately not possible with App Inventor, you only can open Whatsapp like this http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 17 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) or you can prepare the message in App Inventor and pick a contact from the Contact Picker in Whatsapp to send it like this Download aia file for App Inventor (example 1) (https://downloads.sourceforge.net/project/puravidaapps/whatsapp.aia) Download aia file for App Inventor (example 2) (https://downloads.sourceforge.net/project/puravidaapps/whatsapp2.aia) Back to top of page ... How to execute statements in the Jackpal Terminal Emulator Terminal Emulator for Android is a terminal emulator for communicating with the built-in Android shell. It emulates a reasonably large subset of Digital Equipment Corporation VT-100 terminal codes, so that programs like "vi", "Emacs" and "NetHack" will display properly. Download the Terminal Emulator for Android from Google Play (https://play.google.com/store/apps/details? id=jackpal.androidterm). Thank you Richard for being the sponsor of this snippet! I just followed the documentation (https://github.com/jackpal/Android-Terminal-Emulator/wiki/Launching-Terminal-Emulator-forAndroid-from-another-App) and translated this into the following blocks. http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 18 of 31 AjPafucterkarptaVhlai.dat,naydoAruopihpdastvee(rimntod.pmeexor.mdpihifsypst)hioenm.RAaUpnpNifse_s(Satp,CpyRso.IupPhTcpa)tno use AppToMarket for that. geStntihpipsertus n(snninipgp.ets.php) You have to add the permission Tutorials (tutorials.php) News (news.php) The manifest looks like this in the end: Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/terminal.aia) Download apk file (https://downloads.sourceforge.net/project/puravidaapps/terminal.apk) Back to top of page ... Other Basic Stuff App Inventor and the Screen Size The screen size of some older phone models is 320 x 480 pixels in portrait mode. The current version of App Inventor (Android API 3) uses that size. Thank you Jos! To demonstrate that, I used Scott's example (https://groups.google.com/d/msg/appinventor-developers-library/jqFDlqNbr-A/_axfS4B30JEJ) and a Samsung Galaxy Tab 10.1N. The first screenshot is the app after packaging through App Inventor (screen size =545 x 295), the second screenshot after additionally going through AppToMarket and setting the screen to "Any" (screen size = 1280 x 727). See also some recommendations from Gareth here (https://groups.google.com/d/topic/appinventor/eYb8G7Vs6xQ/discussion). Also the Universal Screen Size tutorial (http://www.imagnity.com/tutorials/app-inventor/universal-screen-size-using-app-inventor/) by Saj might help. Back to top of page ... How to build a simple compass app with App Inventor Compass card image from Wikipedia (https://en.wikipedia.org/wiki/File:Brosen_windrose.svg) by Brosen (https://commons.wikimedia.org/wiki/User:Brosen). Thank you! http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 19 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://code.google.com/p/puravidaapps/downloads/detail?name=compass.aia) Back to top of page ... An enhancement to the compass app to provide additionally the direction to a waypoint It was asked in the forum (https://groups.google.com/d/msg/mitappinventortest/qSkHIeZA5rk/yWh8DEVts74J): I had a question about using a compass direction that points to one specific Adress or coordinate instead of just the north. We will have to do some calculations: you can calculate the bearing (https://en.wikipedia.org/wiki/Bearing_%28navigation%29) according to the formula provided here http://www.movable-type.co.uk/scripts/latlong.html (http://www.movabletype.co.uk/scripts/latlong.html). Then to get the direction to the waypoint, just calculate azimuth - bearing (in a range between 0 and 360 degrees), see screenshots. The example points to the famous whalestail in Uvita, Costa Rica http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 20 of 31 (Phuttrpas:V//widwawA.gpoposgl(ei.ncdoemx/m.pahpps)/@9.A1p4p5s4(8a6p9p,s-.8p3hp.7)6182S6n,i4pp2e8t8sm(s/ndipaptaet=s!.3pmhp1) !1e3T?uhtol=rieanls).(tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/bearing.aia) Back to top of page ... How to trigger something if device is facing down http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 21 of 31 sPouIutrnhadaVsifibdtheaeeAndpeavpsikscee(diinsindfaethcxein.pgfohdrpuom)wn(h. tIAt'mppspu:s/s/g(ianrpogpustph.pseh.gpo) AogccleeS.lcneoiprmopme/dtse/mt(essnr giSp/peaenptspso.ipnrhvpe)ntor/T5uNtoerUiasls2(Htu0tcoqriYal/st.CphXp9)z9yqNLeRw4sJ(n) ehwosw.pthop)trigger a (http://ai2.appinventor.mit.edu/reference/components/sensors.html#AccelerometerSensor) for the example, because this sensor oFoffreurmssa(cfocreulmer.pahtipo)n in tLhienkZs-(dliinmkse.nphspio)n. ThSaenarkchyo(suearcfhre.pehspf)x.co.Cukon(thatcttp(:c//ownwtawct..fprhepe)sfx.co.uk) for the car alarm sound. Download aia file for App Inventor 2 (https://code.google.com/p/puravidaapps/downloads/detail?name=accelerometer.aia) Back to top of page ... How to create a nested listpicker It has been asked in the forum (https://groups.google.com/forum/#!topic/programming-with-app-inventor/Fgc9H1RvLBw): I need a main listpicker with different sublists of items below them depending which main list item is selected. For the solution presented here, I'm using 2 listpicker, the second listpicker for the sublists is hidden and will be opened with the listpicker.open block. How does this work: Using the first listpicker you select the main category, in the example "Fruit" or "Vegetables". Lets assume, you picked "Fruit", which means selection index = 1. Using the same selection index and the select list item block you select the corresponding sublist of listDetail, in the example these are Apple Banana Mango and Orange to display them in the second listpicker. Jay Dee asked in the forum" (https://groups.google.com/d/msg/mitappinventortest/sSkYTefjc0k/z9vb1tn7D8sJ): I am still having trouble figuring out how to put an email and number for each name. When I click on Apple I want to be able to see: Apple 555-555-5555 (and if I click it, it will dial the number) apple@gmail.com (and if I click it, it will open up an email) That's a nice example to learn how to work with list of lists. I adjusted my nested listpicker example, you can find it here (https://groups.google.com/d/msg/mitappinventortest/sSkYTefjc0k/SzRrHwwSp2IJ). http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 22 of 31 BPauDcrokawtVoniltodoaapdAoafpiappafsiglee(ifn.o.d.r eAxp.pphInpv)entorA2pp(hs t(tappsp:s//.cpohdp)e.gooSgnliep.pceotsm(/spn/ippuperatsv.pidhapa) pps/Tduotowrniallosa(dtust/odreiatlas.ipl?hnpa) me=Nneewsste(ndeliwsstp.pichkpe) r.aia) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) How to get a date in format YYYY-MM-DD For the leadingZeros procedure, see below. Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/getdate.aia) Back to top of page ... How to get leading zeros in App Inventor Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 23 of 31 How to get the Day of Year Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Just use the Clock.Now block to get loads of information, then use a parse procedure to extract the day of year (see snippet bFoerluomws).(fNoorutme:.pAhsp)Hal sLainidks (liinnktsh.pishpth) readSearch (search.php) Contact (contact.php) (https://groups.google.com/d/msg/mitappinventortest/kofUEubkVV8/XrO78pRJa3EJAs), this is an undocumented feature. It's unlikely that this will change, but you have to use this on your own risk. Btw. the ZONE_OFFSET gives you the difference of the current timezone to UTC in milliseconds. In the example -21600000 milliseconds is -6 hours. (i.e. Costa Rican time = UTC - 6 hours). Thank you Greg! (https://groups.google.com/forum/#! category-topic/mitappinventortest/whUeD4FWA-k) How to parse a result Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/parse.aia) Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 24 of 31 How to use the Sound Recorder Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) It has been asked Forums (forum.php) in the forum (https://groups.google.com/d/msg/mitappinventortest/MQPSTw5m834/yjoBJF-1f90J): Links (links.php) Search (search.php) Contact (contact.php) I'm very new to this and would like to use the SoundRecorder but have no idea how it works and unable to find any example. I now prepared an example for you: Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/soundrecorder.aia) Back to top of page ... New formatting possibilities with the Notifier According to the documentation of the notifier component (http://ai2.appinventor.mit.edu/reference/components/userinterface.html#Notifier) we now can use some HTML for the formatting: The messages in the dialogs (but not the alert) can be formatted using the following HTML tags: , ,
    ,
    , , ,
    , , , , , , , . You can also use the font tag to specify color, for example, . Some of the available color names are aqua, black, blue, fuchsia, green, grey, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. Note: You might have to build your app to see the results! Thank you Hal for the example. Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/notify.aia) Download apk file (https://downloads.sourceforge.net/project/puravidaapps/notify.apk) Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 25 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) How to play a random sound when the device is shaken Thank you SoundFx (http://www.flashkit.com/soundfx/Cartoon/Boings) for the sounds. Download aia file for App Inventor (https://downloads.sourceforge.net/project/puravidaapps/randomsound.aia) Back to top of page ... How does the lookup in pairs block work? http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 26 of 31 SPtuorrae Vtaigd/avaAlupeppsai(risndineax.lipsht tpo)be able to easily search for a tag and get back Apps (apps.php) Snippets (snippets.php) the corresponding value Tutorials (tutorials.php) from the list. News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/lookupInPairs.aia) Back to top of page ... How to pick a random item from a list without picking duplicates? In this example I use the random integer (http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#randomint) block instead of the pick a random item (http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#pickrandomitem) block. The picked item will be removed from the list after displaying it. Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/removerandom.aia) Back to top of page ... How to take a picture or pick an image and share it http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 27 of 31 FPourratheViIdmaagAepppicske(irn, ddoexn.opthfopr)get to add file:// to the Apps (apps.php) provided path to the image... Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/share.aia) Back to top of page ... A workaround for the decimal separator problem The Android, Where's My Car? (http://appinventor.mit.edu/explore/ai2/android-wheres-my-car.html) tutorial does not work for devices, which use a comma as decimal separator: this is, because the location sensor provides numeric values with comma as decimal separator in this case. The Googe Maps app however expects values with dot as decimal separator to work correctly. So how to fix this issue? The answer is simple: just use the replace all block to replace comma by dot. I prepared a custom procedure for that, see screenshot, you also could use the replace all block directly. Also if you develop an app in North America http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 28 of 31 aPnudrayoVuidwaanAtptopsbe(isnudreexth.paht pit )also can be used in Apps (apps.php) Europe without decimal point issues, just use the Snippets (snippets.php) Tutorials (tutorials.php) replace all block... News (news.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Back to top of page ... How to get european or chinese characters from Web ResponseContent It has been asked in the forum (https://groups.google.com/d/msg/mitappinventortest/fvJsC-Zn3G4/UId9dmKI0yMJ): why chinese word can't work from web reponsecontent? Well, as you can see it works: I stored a text file with spanish, german and chinese characters in a text document. Important: To get this working, you have to store the text in UTF-8 format, see screenshot of notpad "Save As" dialog. Note: I'm using a german version of notepad here. Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/webget.aia) Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 29 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) How to use the YandexTranslate component Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) See the documentation (http://ai2.appinventor.mit.edu/reference/components/media.html#YandexTranslate) and http://api.yandex.com/translate/ (http://api.yandex.com/translate/) for more information, including the list of available languages and the meanings of the language codes and status codes. Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/yandex.aia) Back to top of page ... How to read a file stored as asset in App Inventor The file component is very easy to use, see also the the documentation (http://ai2.appinventor.mit.edu/reference/components/storage.html#File) how to use it. You also might be interested in How to append text to a file stored as asset in App Inventor (https://groups.google.com/d/msg/mitappinventortest/HZ09P-vxaV4/awlitSZP0XcJ). Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/readfile.aia) Back to top of page ... http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 30 of 31 How to keep the screen on Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) You add a notifier and a clock, not used for other purposes in your app. Set the clock to a rather long interval, 10 seconds or so. MFoaruymbes (efovreunma.phmpi)nuteLwinokusld(linwkosr.pkhfpin)e, deSpeearncdhin(sgeaorncht.hpehps)ettinCgoonftaycotu(cropnhtaocnt.ep.hMp)ake the background color of the notifier transparent. When the clock.timer fires, display a warning that is an empty string. In this way you will not see it, because of the transparent background. It keeps your phone awake for as long as you want and as long as your battery stays alive (which may be considerably shorter). Note: description by Chica copied from here (http://ai2.appinventor.mit.edu/reference/components/storage.html#File). Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/screenOn.aia) Back to top of page ... How to create a directory The file component unfortunately can't create a directory, but we can use the Canvas as workaround. Download aia file for App Inventor 2 (https://downloads.sourceforge.net/project/puravidaapps/createDirectory.aia) Back to top of page ... (https://creativecommons.org/licenses/by-sa/3.0/) This work by Pura Vida Apps (https://puravidaapps.com) is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License (https://creativecommons.org/licenses/by-sa/3.0/) with attribution (name=Pura Vida Apps (https://puravidaapps.com) and link to the source site) required. http://puravidaapps.com/snippets.php 5/8/2015 App Inventor Code Snippets | Pura Vida Apps Page 31 of 31 Pura Vida Apps (index.php) Apps (apps.php) Snippets (snippets.php) Tutorials (tutorials.php) News (news.php) Home (./index.php) | Apps (./apps.php) | Snippets (./snippets.php) | Tutorials (./tutorials.php) | News (./news.php) | Forums (./forum.php) | Links (./links.php) | Search (./search.php) | Contact (./contact.php) Forums (forum.php) Links (links.php) Search (search.php) Contact (contact.php) Site Content © 2015 Pura Vida Apps (http://puravidaapps.com) using the Foundation Framework (http://foundation.zurb.com/). Portions of this page are modifications based on work created and shared by Google (http://code.google.com/policies.html) and used according to terms described in the Creative Commons 3.0 Attribution License. (http://creativecommons.org/licenses/by/3.0/) Android is a trademark of Google Inc. http://puravidaapps.com/snippets.php 5/8/2015

    Top_arrow
    回到顶部
    EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高进,我们会尽快处理。