Skip to first unread message

Luigi Muscettola

unread,
May 31, 2017, 4:56:27 AM5/31/17
to MIT App Inventor Forum
Hi,

I am developing an app with Appinventor2 that has the goal to open another app (APP1) installed on the same smartphone and activate a switch button that should send via web a command to open/close a doorlock

I started trying to simulate how the Activity starter component works by using the app ActivityStarter ( see https://play.google.com/store/apps/details?id=appinventor.ai_mletsch80.AppInvActivityStarter&hl=itand playing with it in order to obtaing the requested actions.

I am currently experiencing the following situation:

1) Following the advise in the appinventor documentation I observed the logcat of the APP1 and saw the Activity Package and the Activity class and put them in the ActivityStarter app fields. Clicking on the startactivity button I obtained to let the APP1 open and position in the screen with the switch button on it.

2) My goal now is to effect the activation of the switch (i.e. the command to open and to close the doorlock).
Looking at the logcat I detected a string that I think is associated to the action of opening or closing the door. 

I attach below the extract of the string

05-30 08:21:11.988 30828 30963 D Retrofit: Content-Type: application/x-www-form-urlencoded; charset=UTF-8

05-30 08:21:11.988 30828 30963 D Retrofit: Content-Length: 509

05-30 08:21:11.988 30828 30963 D Retrofit: cmd=app.log&User-Agent=Android-Ivory&idu=IDOWNER&idp=PWDOWNER&and_pn_reg=APA91bE8Hq0x3X7HlKO2vOIw_2qMiJV_-VfnMUv4IYeGhaklAWOTtHWDpsxWIawQnWuBNOA5ggUOFmiw8-7ZYWCBvvJgUGTi-5zV1JZLutrCgz44bAonU1M37WXpVOzVfsY14dPmbfui&idi=02%3A00%3A00%3A00%3A00%3A00&log_0=%7B%22mac%22%3A%22D4%3AB3%3A9A%3A98%3A5E%3A71%22%2C%22eventid%22%3A1%2C%22phonetime%22%3A1496125271%2C%22tsmb%22%3A0%2C%22batterylevel%22%3A100%2C%22errorcount%22%3A2%2C%22latchcount%22%3A107%2C%22unlatchcount%22%3A100%2C%22locktime%22%3A1496125328%7D

05-30 08:21:11.988 30828 30963 D Retrofit: ---> END HTTP (509-byte body)



As far as I have understood of the ActivityStarter I think that I have to input this command in the DATAURI field in a way that can be acceptable and effective. I tried to do it but the result was that the start activity open correctly the APP1 on the screen of the switch but it doesn't activate the switch.

I would be grateful to you if you could advise me on how to find the correct syntax or how to use parts of the string above and input them into the ActivityStarter fields to obtain the goal.

I would appreciate moreover if you could indicate articles or tutorials, if they exists, on the usage of the ActivityStarter app and on the methods to build the activity starter component elements (URI, Category etc.), which I believe is the most difficult task to accomplish in order to use effectively this component

Thanks for your cooperation
Luigi

Juan Antonio

unread,
Jun 1, 2017, 4:31:11 PM6/1/17
to MIT App Inventor Forum
Hi Luigi, this is a Spanish tutorial. 

An App Inventor app send two data ( 8 4) to other App Inventor app, this add data 8 + 4 and return result to first app (12).


Regards.


Luigi Muscettola

unread,
Jun 2, 2017, 3:54:09 AM6/2/17
to MIT App Inventor Forum
Hi Juan Antonio
and thanks for your suggestions and link with your example.
The problem here is a little more complicated for these reasons:

1) the second app, the one executing the doorlock commands (to open or close the lock), is not created by me with appinventor but it is supplied by the doorlock manufacturer.
2) I don't know therefore the intent name, the category to use or other parameters that I should be send through the activity starter component in order to obtain the goal
3) following the advice by Taifun and Appinventor documentation ( see below)

Figuring out how to set the properties

If you can't find documentation for the activities you want to start, one way to figure out how to set the properties is to start up the activity manually and look at what appears in the Android System Log. For example, if you use YouTube to play a video, you'll see in the log:

I/ActivityManager( 86): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://www.youtube.com/watch?v=8ADwPLSFeY8 flg=0x3800000 cmp=com.google.android.youtube/.PlayerActivity }

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. As in the YouTube example, there may also be "dat=" information that can specify with the DataUri property.

Starting arbitrary apps

You can use the Activity Starter to start any activity at all if you know the package name and class name, or the appropriate intent. Some developers document these intents for the benefit of other Android developers. For hints on starting other apps using intents, see the Android API documentation or search the Android developer forums.

If you have an app on your phone and you don't have the source code, 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, as indicated above.


I observed the logcat of the APP1 application and I found the Application Packeage and Class so that using the Activity Starter tool I was able to start the activity and to open the target app (APP1) and to reach the screen with the button commanding the opening/closing of the door. I wasn't able though to activate the command. I guess that this is a matter of giving the proper Parameters, intent action etc. to the Activity starter tool in order to accomplish this additional step. To this regard, by looking at the logcat I detected a string (the one enclosed in my previous message, in which was visible a HTTP POST which reminds me a command that should activate the lock). I thought it could have been input as a Datauri parameter and I tried to start the activity with it, but it was unsuccesful.


I would therefore be grateful to anybody can give me some advice on 1) if I am on the right path, 2) what can be the right syntax or way to input the Datauri command 3) if there are other elements that I should input in the Activty Starter to reach the goal.


Thanks to you Antonio and to anybody else that will help me


Luigi



Luigi Muscettola

unread,
Jun 5, 2017, 11:31:43 AM6/5/17
to MIT App Inventor Forum
Hi everybody,

Can anybody tell me if I am complitely out of path or if I can accomplish what I would like, according to my previous posts?

I guess that the question is kind of complex but I really would like to come up with a solution (if possible).

Maybe another way to face the problem would be to write a script in java (or javascript) that can send the HTTPS POST and make it run prom the appinventor application. (I saw that a similar suggestion was given by Taifun in another post).

I would greatly appreciate to receive a feedback.
Thanks
Luigi

Reply all
Reply to author
Forward
0 new messages