2016년 12월 18일 일요일

Using the Activity Starter Component

The Activity Starter component lets you combine applications by having one application start up other applications.  It's a key way to extend the capabilities of App Inventor by taking advantage of other  apps, whether they are apps created with App Inventor or or whether they are “external apps” (i.e., apps that were not created with App Inventor).  These can be App Inventor apps created by you or others.   They can also be apps like Camera and Maps that are pre-installed on the device.  Or they be any app at all as long as you have the necessary information to provide to the activity starter.  You can also pass values to applications when you start them, as well as get back results from from applications to use in further processing.   In addition, advanced developers who work with the Android SDK can create original apps that can start App Inventor apps, and be started by them.
To start an application with the Activity Starter, you must supply certain control information to the Android operating system. You do this by setting various properties of Activity Starter before calling the ActivityStarter.StartActivity method. This section gives some examples.

Starting Other App Inventor Applications

You can use the Activity Starter to start another app that was created with App Inventor.   This is similar to using OpenAnotherScreen in multiple screen applications, except that now we’re dealing with two separate applications rather than two screens within a single application.  To open the other application, you need to know its package name and class name. If you have the source code of the App Inventor app (aia file), you can find these names as follows:

1. Download the source code to your computer.
2. Using a file explorer or unzip utility, find the file called youngandroidproject/project.properties .
3. The first line will start with " main= ". Everything after that is the package and class name.
For example, here is a first line you might see for an App named HelloPurr.
main=appinventor.ai_ElsaArendelle.HelloPurr
The ElsaArendelle part of the name comes from the App Inventor user account.
To start this app, you would use an activity starter component and set these properties:
ActivityPackage: appinventor.ai_ElsaArendelle.HelloPurr

ActivityClass: appinventor.ai_ElsaArendelle.HelloPurr.Screen1

Invoking the activity starter's StartActivity method will start HelloPurr. When HelloPurr finishes (if it does), the original app's AfterActivity method will be invoked.
If you are going to start another App Inventor app, make sure you use the correct package name. For example, if someone posts the source code (aia file) for an app, and you repackage that app, you'll end up with a different package name than the original.

Starting a Built-in Android Application from your App Inventor App

Apps that come built in with the Android device can be invoked “explicitly” by using package names and class names, as above.   They can also be started “implicitly” by specifying an Action, in which case the Android operating system can figure out which actual application to start.  The information used to start an app is called an intent, and the process for determining which application to start is called intent resolution.  You can find information about intents in the Android system documentation on intents and intent filters.
Some apps are designed to accept extra information when they are launched. For example, the Android Map activity can accept geographic information that specifies a location to display.   You must consult the documentation for the particular app to learn what this extra information is and how to specify it.  You can also find information on  Android  Common Intents for Google Android applications available on most device.
Generally, you specify the information by setting the ActivityStarter's properties just before the you launch the other app with StartActivity.  You can set these in App Inventor using the ActivityStarter properties DataType and DataURI.  There is also an Extras property that takes a list of keys and values and specifies the property values for the corresponding keys.  The particular values you have to set depend on the activity you want to launch.
Here are some examples.

Warning: The values in these examples depend on the version of the Android operating system on the app user’s device.  If you are creating an app that will be used on many different devices, you can run the ActivityStarter.ResolveActivity command to test whether the activity you need is supported on the user’s device and generate an appropriate error message if it is not supported.

Start the Camera

To launch the Android Camera app, use an activity starter with the IMAGE_CAPTURE Action property. You do not specify an ActivityPackage or an ActivityClass:

Action: android.media.action.IMAGE_CAPTURE

This is basically what the App Inventor Camera component does, although it is more convenient to use the Camera component than to use the ActivityStarter in building your app.

Launch a Web search

To launch a Web search, use an ActivityStarter with the WEB_SEARCH action.  The user’s phone will display a menu asking what kind of search to perform:

Action: android.intent.action.WEB_SEARCH

Open the browser to a designated Web page

Use these ActivityStarter with the VIEW action and a DataUri  to open the phone’s browser to a designated web page, for example,

Action: android.intent.action.VIEW

DataUri: http://mit.edu

Start the mailer with pre-addressed message

To start the Android mailer application, use the VIEW action and set the DataUri property to specify the recipient, the subject, and the body of the message. In each case, starting the activity will bring up the Android mailer, and you can complete the message and then press "Send".
For instance, if you specify:

Action: android.intent.action.VIEW

DataUri: mailto:santa@northpole.com

then starting the activity will bring up the mailer, with the addressee filled in.  

You can use the mailer application to edit this before sending the message, if you prefer.

You can also specify the subject line and the message text with the aid EXTRA properties.  For example, to send email when a button is pressed, you could use:

 Screen Shot 2015-07-18 at 6.21.04 PM.pngObserve how EXTRAS is a list, where each element is a key, value pair.

Show a map for a location

If you know a latitude and a longitude, you can use the VIEW action to show a map of the area:

Action: android.intent.action.VIEW

DataUri: geo:37.8,-122.23?z=10

The DataURI here specifies the latitude and longitude and also a zoom value of 10 (z=10).  Zoom value is optional and ranges from 1 (the entire Earth) to 23.
If you know a zip code of a location, you can set the activity starter properties as follows:

Action: android.intent.action.VIEW

DataUri: geo:0,0?q=94043

If you have a street address, you can use a DataUri that encodes the address with a scheme called URL encoding :

Action: android.intent.action.VIEW

DataUri: geo:0,0?q=77+Massachusetts+Avenue%2C+Cambridge%2C+MA

Generally in URL encoding you have to replace spaces (with  %20 or plus sign ) and punctuation marks, such as comma ( %2C ) and period ( %2E ).

Play a YouTube video

You'll need to know the URI of the YouTube video. Then set the Activity Starter action to VIEW, and set the  Data URI to vnd.youtube followed by the YouTube URI of the video to be played, for example

Action: android.intent.action.VIEW

DataUri: vnd.youtube:nAPk9ycCbfc

Select a contact

To choose a contact, use an ActivityStarter with the PICK action. The contact will be returned in the form of uri and stored in the Activity Starter’s ResultUri property

Action: android.intent.action.PICK

Starting other external apps

You can use the Activity Starter to start any activity at all.  You’ll need to  know the package name and class name, or the appropriate intent.  Some third-party application developers document this information. For hints on starting external apps, see the Android API documentation or search the Android developer forums.

Discovering how to set the ActivityStarter properties

If you want to start an app and you you don't have the source code or documentation, you might still be able figure out the package name and class name (and sometimes the intent) by launching the app and inspecting the Android system log.

For example, if you use the YouTube application to play a video, you'll see in the log:

I/ActivityManager(   86): Starting activity: Intent { act=android.intent.action.VIEW dat=vnd.youtube:nAPk9ycCbfc cmp=com.google.android.youtube/.PlayerActivity }

If you can find the "cmp=" string, then the ActivityPackage is the part before the slash, e.g.,  com.google.android.youtube.  The ActivityClass is is the entire "cmp=" part, without the slash character, e.g., com.google.android.youtube.PlayerActivity.   There may also in general be "dat=" information that should be specify as the DataUri property.

Example: Starting  an external app to pick files

AndExplorer from Lysesoft is an application that lets you pick files from your phone’s file system. You can use AndExplorer with an activity starter to add a file picking capability to your application. If you have AndExplorer installed on your phone, you can pick a file from your App Inventor app by setting the following Activity Starter properties:

Action: android.intent.action.PICK

dataType: vnd.android.cursor.dir/lysesoft.andexplorer.file

dataURI: file:///sdcard

When AndExplorer runs, it will display lists of files and let you pick one.  When AndExplorer finishes and ActivityStarter.AfterActivity is called, the resulting file name will be available as the value of ActivityStarter’s  ResultUri property.  In addition, ResultType will give the type of the file, for example, image/jpeg or audio/mpeg. Using this information, you can build an App Inventor app that lets you pick a file from the file system and displays the image if you’d picked a jpeg file, or plays a music track if you picked an mpeg file.
This example also illustrates how the external app can return values to the App Inventor app. For more information, see  “Returning results from external apps to App Inventor apps” below.

Passing values between applications

In the general situation, an App A can start an App B.  App A can also start App B and pass it a startup value, and App B can return a result to App A when it terminates.   The details of how this is accomplished depend on the specific apps, and on whether the App Inventor app is the app that is doing the starting, or the app being started, or both.  See the appendix below for hints on creating external apps that interact with App Inventor apps.

Using the activity starter with two App Inventor Apps

App Inventor screens are activities, so you can use the Activity Starter to start other App Inventor apps.   The Hello Purr example at the top of this page shows how to do this. This is basically how App Inventor’s multiple screen apps work.  
To pass a startup text value to the App Inventor app you are starting with the Activity Starter, ise EXTRAS to set the KEY property to the string APP_INVENTOR_START and set the VALUE Property to the text you want to pass.  The other app can then retrieve this value with Get Start Plain Text.   To return a value from the other app, use Close Screen With Plain Text. 
For the case of two App Inventor apps, it’s simpler to design the combination as a single multiple screen app, rather than create two separate apps that communicate using the Activity Starter.   But one situation where you might want to have separate apps is where two people are loosely collaborating on a project and want to work separately.  Remember that in order to run the combined app, users must have both applications installed on their devices.

Is the application available on the device?

If your app tries to start other apps, you'll want to check that those other apps are available on your user's phone before trying to start them. You can determine this using the ActivityStarter.ResolveActivity , which returns the name of the Activity that would be started by ActivityStarter.StartActivity, given the package or other information you've provided. If this name is blank, then the required application is not present, and you can make your app alert the user.

Appendix:  Technical information  for Android developers who are designing external apps for use with  App Inventor apps

If you build Android apps using the Android SDK, you can design external apps that start App Inventor apps and you can also design apps can be started by App Inventor apps.  You can also arrange to pass values between the App Inventor apps and the external apps.

Returning results from external apps to App Inventor apps

The AndExplorer example above shows how  external apps can make results available as properties of the Activity Starter when the app terminates.    In the case of AndExplorer, the properties were ResultType and ResultUri.   To know this information about AndExplorer, you’d need to find documentation for AndExplorer or see examples of Android code that uses it.
In general when your external app finishes and returns an intent to the App Inventor app that started it, the value of Intent.type() will be available as the ActivityStarter.ResultType property.  Similarly, the will be the value of Intent.getDataString() will be available as the  ResultUri property.
You can also pass back other information in the intent.   Choose a name (Java String) for the result and have the App Inventor apps set that name to be the ResultName property of the activity starter.  To return a desired value from your external app in an intent, use Intent.putextra(chosenResultNamedesiredValue).   When your external app finishes, the App Inventor ActivityStarter.AfterActivity() event will be signalled, and the result parameter to event handler will be the desired value.  That same desired value will also be available as the Activity Starter’s Result property.  The desired value must be a string, and you can return only one value using this method.

Starting App Inventor apps from external apps

To start an App Inventor activity from an external app, use the Java Android methods startActitvity() or startActivityForResult().  To pass a startup value, include that value in the intent, by invoking the method  Intent.putExtra(tag, value) where tag is the string APP_INVENTOR_START.   The App Inventor app being started can then access the corresponding value with the screen’s Get Start Plain Start Text method.

Returning results from App Inventor apps to external apps

When the App Inventor app that you started finishes (more technically, when the current screen closes with CloseScreen), it will signal onActivityResult() to the external app that started it.   The App Inventor app can pass back a text string value by using Close Screen With Plain Text.  That value will be available to the external app through the returned Intent as Intent.getStringExtra(APP_INVENTOR_RESULT).
        
Creative Commons License

Setting up activitystarter for qr droid


I like to use in my program for creating qr code whichprovides program QR Droid. Here is a guide to the author of the program, but I do not know how to use it in the App Inventorhttp://qrdroid.com/android-developers/#4

Encode (Generate)

✫ Action: You must use this action: la.droid.qr.encode
Intent qrDroid = new Intent( “la.droid.qr.encode” );

✫ Mandatory parameter: You MUST provide text to be encoded (QR code contents) by seting extra “la.droid.qr.code“.
qrDroid.putExtra(“la.droid.qr.code”, “This will be QR code content”);

✫ Optional parameter “size”: By default, QR code size will be automatic, according to with of screen of device. If you want to override this, you can set “la.droid.qr.size” in pixels.
qrDroid.putExtra( “la.droid.qr.size” , 150);

✫ Optional parameter “image”: By default, QR Droid will return to you a full path of generated QR code using Google API, so no image will be really generated and result will start with http://chart.apis.google.com/chart. If you prefer, you can set parameter “la.droid.qr.image” to make QR Droid create this image in user’s SD card and return a local path (ex: /sdcard/QrDroid/tmp/QrDroid_123.png)

qrDroid.putExtra( “la.droid.qr.image” , true);

✫ Call:
startActivityForResult(qrDroid, 0);

✫ Result: Inside onActivityResult(int requestCode, int resultCode, Intent data), you must read result as String. It will contain a remote URL or a local path.
String result = data.getExtras().getString(“la.droid.qr.result”);

-- 
see here Using the Activity Starter
and see several Activity Starter examples here https://puravidaapps.com/snippets.php#2activity

now try something, see also

and if you get stuck, then 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.

-- 
Can you use the Barcode scanner built in to the sensor components to scan your QR code - saves a lot of work?


-- 
-- 
Thanks for help.

I have used puravida and works.

-- 

Parsing a web page content opened in an external browser with activity starter


My company has a web application with a login page. I want to login and then to parse the content of a web page. Any user in the company needs to be able to use the app.

I tried :

✫ the web component but login cannot be done by any user in the login web page

✫ the internal web browser. I may login but I cannot parse a web page content 

✫ an external web browser (with activity starter). I may login but I don't know how to parse a web page content

Is it possible to parse a web page content opened in an external browser with activity starter ? Sorry if the same question as been already asked. I couldn't find it.

-- 
this example might help https://puravidaapps.com/filedownload.php




Is it possible to parse a web page content opened in an external browser with activity starter ? 
no

-- 
Thank you for the reply ! But your example uses the web component. With the web component, as far as I understood, company users will not be able to login because they will not be able to type username and password in the login page.

-- 
just use your own login screen (2 textboxes)  and pass user and password in the web component as shown in the example


my tools extension can base64 encode the user:password string...
 base64Encode.JPG
however this will work only for basic HTTP authentication, you did not mention, what your company is using...

-- 

Best Apps 2016


I just saw that Thunkable is having a competition to submit Best Apps of 2016. If anyone from here wants to submit, you can just upload your  AI .aia to Thunkable and submit. Just wanted to share this opportunity to have your work featured. Deadline: 12/31

See details below:

--
Its only for apps that are made with thunkable and not with ai2.

--


app of the month code


Wondering if it is possible to get the code for "app of the month" applications (under news and resources tab)?  If yes, how or where?

--
You can click on the app's icon under the name of the winner to open the app description in the App Inventor gallery. From there you can click "Open App" and AppInventor will make a copy under your personal account that you can explore and modify.

--
Thanks Evan.

-- 


difference with android studio


hi, i have a silly noob question.

i just discovered android studio and i'd like to know what are the different potentiality respect app inventor.

I'm not using it, and i'm learning now app inventor that's a great great tool...and i'm learning thanks to users and expecially to the great man abraham.

just curiosity

-- 
If you want to use a learning tool and want to understand the basics of programming, then App Inventor is your best friend (and Abraham). Besides, you get real Android apps.
If you want to become a programmer, want to learn the Java programming language, and become a professional at writing Android apps, then Android Studio is for you.
Also, it takes days to write your first App Inventor appand months to become good at it. For Android Studio, it may take one or two years, depending on your previous knowledge about programming.
-- 
Here's a YouTube video by the great Derek Banas showing how to convert an AI2 app to Java:
Hint:  Drink 2 cups of coffee before starting the video, and hang on tight.

-- 


-- 

resources of sensors


how to choose an app according to sensors

--
Can you give more detail? Which sensors are you talking about and where do you want to choose the app from?

-- 
sensors that check about weather changes. what do you mean where to choose the app from?

--
You asked yourself how to choose an app, therefore my question what kind of app you want to choose!
These weather sensors, are they attached to an Arduino board, or what do they look like?

--

filter bar


Some months ago, i posted to know how to erase listeview filter bar in one click. I also made exhaustives searchs...

It's just impossible. and i do not want to use jquery.
So finally do you think please, that you could modify the filterbar to insert a "erase all" element?

I think that it will benefit everibody. Thank you.

-- 
Not clear on your question. 
Are you looking for ability to just reset your list and just clear it from all elements??
If YES, then why do you want to use the SEARCH BAR?? 

-- 
No, i just need to erase the filter bar content instead of using the keybord, because i use a dictionnary and do so many searchs.

I don't want to erase letter by letter at every new search, or use long press on the bar to select the entire word and erase.
one click erase is more effective. Many users of my dictionnary are asking for that.

-- 

No, i just need to erase the filter bar content instead of using the keybord, because i use a dictionnary and do so many searchs.

I don't want to erase letter by letter at every new search, or use long press on the bar to select the entire word and erase.
one click erase is more effective. Many users of my dictionnary are asking for that.

--
 

problem with app inventor 2


im very interesting to create a app like "sirioforandroid" which is present also in the gallery of MIT app inventor 2...but when i try on my phone it doesn't answer me....my phone's android version is 6.0....please help me....when i try whith only a question it woks,but when i put the duplicate question it doesen't work anymore...please....answer me....thank youvery much.

--
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 answer.....my blocks is this

-- 
please add your screnshot into this thread. thank you.

-- 
ok ...thanks Taifun.....in this way is correct?
5c7b6-clip-44kb(1).png 표시 중
-- 
try to speak a few times "Pizza Margherita" to find out, which word combinations the speech recognizer returns as result... you will have to check for all these words, the speech recognizer is not very reliable to understand words exactly... also you might want to convert all words into lower case, the contains text block is case sensitive...

-- 
Thanks so much...you are very kind......i resolve it also with the word combination....it was a problem only of word........i would ask to you another think..... if i want to make Pizza Margerita 1,2,3,4 5 = 5 euro  and Pizza marrgherita 6,7,8,9= 6 euro......how can i make this function???????or if i want make Pizza margerita 2,4,6,8,10,12,14 (equal )= 6 euro ....and Piazza margerita 1,3,5,7,9,11,13,15(odd)= 7 euro.....how can i make this 2 function...???
thank you for the patient.....have a good day my friend.

-- 
i don't understand how can i make,Abraham...can you add a screenshot,please???.....i woud make in a fast way this step....a continuos numbering, odd numbered  or even numbered: Pizza Margherita 1,Pizza Margherita 2,Pizza Margherita 3 = 5 euro                 Pizza Margherita 4,Pizza Margherita 5,Pizza Margherita 6 =7 euro         or  pizza 1,pizza 3, pizza 5, pizza 7(only odd) = 10 euro           pizza 2,pizza 4, pizza 6 , pizza 8(only evenl) = 8 euro.........how can I put in the block that I've posted on here ??? thanks a lot to all of you and good day.

-- 
What do you mean when you say
 Pizza Margherita 4,Pizza Margherita 5,Pizza Margherita 6 =7 euro ?

Do you mean you have three different styles of Pizza Margherita, named

✫ Pizza Margherita 4,
✫ Pizza Margherita 5,
✫ Pizza Margherita 6

and that each of those styles costs 7 euro per slice?

Or do you mean that the number you mention after the pizza type named Pizza Margherita
refers to the quantity of such pizzas to be given to the customer, at 7 euro for the total batch of 4 to 6 pizzas of that type?

-- 
no..in practice I would define the pizza according to miles ... for example a Margherita from 1 to 3 miles costs 5 euro, from 4 to 8 miles cost 6 and so on .... thank you for your interest .. ..really kind.

-- 
See attached for how to do a double value lookup, using a colon (:) between the pizza type and the miles.

I put the lookup table in blocks because it was a small samples and because I was in a rush.

For bigger tables with more miles and pizza types, you will need to switch to a csv file like in this sample:

sample.png 표시 중
blocks.png 표시 중
Designer.png 표시 중







-- 
I have a file in this list .xlsx po ..but how can i do upload it to the project ?? 
convert the table into csv format, just store it as csv file (comma separated values)
then use the file component to read the file and convert the csv table into a list using the list from csv table block

-- 
sEE THIS DOC FOR AN EXAMPLE OF UPLOADING A CSV TABLE INTO THE mEDIA DRAWER AND READING IT IN AN APP...

(DARN CAPS LOCK)

-- 
The only part of my example appropriate for your app is the part that loads the file, at the very start.
Rip out the rest.

In Scrteen1.Initialize, Read the File with the csv text.
Don't read it any where else, since you will then have it available. in the global map.

Since you are doing lookup from the table using speech recognition as your key,
you will need to downshift the csv text as it goies into the table, when it is loaded.
Otherwise, nothing will match.  Speech recognition assumes everything you say is lower case, which does not match upper case.

When a spoken street name arrives, pass it thru the attached filter procedure to look up that text from the map table, using column 2.
The output will be all the rows that match that text in column 2, which you can show in a label and announce via speech.

-- 
Ok...this is my work but don't work lol....Thanks very very much for all your advice

-- 
in this way it returns only my voice and not the results...
62c1d-clip-49kb.png 표시 중
Faro2.aia


--
You never called the procedure
See the chapter on procedures in the book in the FAQ.

--
OK thanks a lot....today i LL try to see  where is my wrong.. .thanks...and have a nice day.


--
i understand how many process i had wrong....thanks to Abraham and taifun,im trying to resolve in these way.....but im stilling wrong something.....can you help me???thank so munch..
faro2prova.jpg 표시 중




-- 
See attached for a much simpler approach.
Going offline for a day, so you will have to test it yourself.

P.S.  Speech recognition is spotty at best.
blocks.png 표시 중
Faro3.aia


-- 

You have to apply Divide and Conquer to the problem.

Is the speech recognition getting the right text?

Is that text exactly in the TinyDB tag collection?


What is you replaced the input text label with a text input box, and typed in the search word, to test the lookup function?

Does the language setting of your device give you proper spelling matching your csv file?
Speech recognition can't reed ewer mined if yew kneed exact spelling to match TinyDB tagz.

-- 

Here's a sample app in the Gallery to test your device's speech recognition:
It should respond to "clap on" and "clap off".

--