romanka...@gmail.com

unread,
Mar 31, 2014, 7:47:21 PM3/31/14
to mitappinv...@googlegroups.com
How do I link a button to a URL to make it open a specific website when someone clicks on it? I can only find information for App Inventor Beta on how to do this...

Thanks!
Roman

SteveJG

unread,
Mar 31, 2014, 8:57:23 PM3/31/14
to mitappinv...@googlegroups.com
Try this.   Most things in AI2 are done almost the same as in AI2.   Next time take a look at the similar blocks available and try to figure out what u need.   It is not hard and no penalty if you guess something incorrectly, but nice if u get it right.




Regards,

Steve

romanka...@gmail.com

unread,
Mar 31, 2014, 9:09:24 PM3/31/14
to mitappinv...@googlegroups.com
Thanks Steve! That worked, but it opens the website in the same page as my app. Is there any way of making it open in an actual web browser?

Roman

SteveJG

unread,
Mar 31, 2014, 9:36:03 PM3/31/14
to
Well, the WebViewer component is a simple web browser.   You can make it open in another screen.   Just put the WebViewer component on Screen2  but make sure you have a way ...a button or use the Control Screen2.BackPressed event handler with code to return to Screen1.        I have not tried it but you might be able to get Activity.Starter to open a particular URL.  Like:

ActivityStarter

A component that can launch an activity using the StartActivity method.

Activities that can be launched include:

  • Starting another App Inventor for Android app. To do so, first find out the class of the other application by downloading the source code and using a file explorer or unzip utility to find a file named "youngandroidproject/project.properties". The first line of the file will start with "main=" and be followed by the class name; for example, main=com.gmail.Bitdiddle.Ben.HelloPurr.Screen1. (The first components indicate that it was created by Ben.Bi...@gmail.com.) To make your ActivityStarter launch this application, set the following properties:
    • ActivityPackage to the class name, dropping the last component (for example, com.gmail.Bitdiddle.Ben.HelloPurr)
    • ActivityClass to the entire class name (for example, com.gmail.Bitdiddle.Ben.HelloPurr.Screen1)
  • Starting the camera application by setting the following properties:
    • Action: android.intent.action.MAIN
    • ActivityPackage: com.android.camera
    • ActivityClass: com.android.camera.Camera
  • Performing web search. Assuming the term you want to search for is "vampire" (feel free to substitute your own choice), set the properties to:
    • Action: android.intent.action.WEB_SEARCH
    • ExtraKey: query
    • ExtraValue: vampire
    • ActivityPackage: com.google.android.providers.enhancedgooglesearch
    • ActivityClass: com.google.android.providers.enhancedgooglesearch.Launcher
  • Opening a browser to a specified web page. Assuming the page you want to go to is "www.facebook.com" (feel free to substitute your own choice), set the properties to:

--Steve


romanka...@gmail.com

unread,
Mar 31, 2014, 11:04:54 PM3/31/14
to mitappinv...@googlegroups.com
Thanks Steve! I will try that next.

phantomfoot

unread,
Apr 1, 2014, 12:39:15 AM4/1/14
to mitappinv...@googlegroups.com, romanka...@gmail.com
Use the activity starter,

Set the following properties
Action: android.intent.action.VIEW
DataUri: http://www.siteurlyouwanttoopen.com


Then call StartActivity.

Source: http://ai2.appinventor.mit.edu/reference/other/activitystarter.html

SteveJG

unread,
Apr 1, 2014, 8:37:56 AM4/1/14
to mitappinv...@googlegroups.com
Steve's suggestion will probably give you exactly what you want (yes, there are at least two Steves here sometimes).

I suggest you do one additional thing, when you add the ActivityStarter;

Adding the AfterActivity block should allow users to return to the original screen after using the ActivityStarter by using the Android's back arrow..   I am not certain you will need this block if you only have 

one screen in your app.

Regards,

SteveJG


Roman

unread,
Apr 5, 2014, 2:40:01 PM4/5/14
to mitappinv...@googlegroups.com
Thank you both! I just released my very first app on the Google Play store :)  (It's called Fútbol = MC2). There is still a lot for me to learn about MIT App Inventor but I'm really enjoying the process and appreciate the community of programmers helping each other out. 
One question that I have is how do I put a space in my app name? When I saved it in MIT App Inventor, I wasn't able to put a space (and I wasn't able to use the u with the accent) in the file, I could only use regular letters and underscores. I tried to rename the APK once it was downloaded on my PC but when the file gets installed on a phone, the file shows up as the name that I saved it as on the App Inventor (i.e. "Futbol"). Any suggestions on how to use spaces and special characters in the app name?

Thanks,
Roman

SteveJG

unread,
Apr 5, 2014, 3:48:40 PM4/5/14
to
Roman, please ask your question in a new thread... I do not know the answer.   I think this would work if your PC language is set to the target language ..I mean, if your browser is in German, German characters probably would work when saving but the special characters, like an umlaut etc. will not work if the browser is displaying in English.   Please post again as I suspect someone will give you better advice if you post a new question asking Can I use foreign alphabet characters in an App Project Name?   or something like that.

SteveJG
Reply all
Reply to author
Forward
0 new messages