Homework: Android Facebook Post - A Mobile Phone Exercise 1. Objectives
Homework: Android Facebook Post - A Mobile Phone Exercise 1. Objectives
1. Objectives
Use Java code with a combination of the Android SDK and Facebook APIs;
2. Background
2.1 Eclipse
Eclipse is an open source community, whose projects are focused on building an open
development platform comprised of extensible frameworks, tools and runtimes for
building, deploying and managing software across the lifecycle.
The Eclipse Project was originally created by IBM in November 2001 and supported by a
consortium of software vendors. The Eclipse Top-Level Project is an open source, robust,
full-featured, commercial-quality, industry platform for the development of highly
integrated tools and rich client applications.
The home page of the Eclipse Foundation is located at:
http://www.eclipse.org/
2.2. Android
Android is a mobile operating system initially developed by Android Inc., a firm
purchased by Google in 2005. Android is based upon a modified version of the Linux
kernel. Unit sales for Android OS smartphones ranked first among all smartphone OS
handsets sold in the U.S. in the second quarter of 2010, at 33%.
The Android operating system software stack consists of Java applications running on a
Java based object oriented application framework on top of Java core libraries running on
a Dalvik virtual machine featuring JIT compilation.
The Official Android home page is located at:
http://www.android.com/
2.3 Facebook
Facebook is a global social networking website that is operated and privately owned by
Facebook, Inc. Users can add friends and send them messages, and update their personal
profiles to notify friends about themselves and what they are doing.
Users can additionally post news feeds to their profiles, and these feeds may include
images, besides text messages.
The facebook homepage is available at:
http://www.facebook.com
A snapshot of the user interface, after clicking the search button, is shown in Figure 2,
before and after selecting one of the tuples.
To implement this exercise you are required to write a Java program using the Android
SDK and the Facebook SDK for Android. The top-level interface consists of two areas:
A control (widget) to select the hotel to post (a combination of text and image);
you can use any available Android control to perform this step (such as the
ListView or Gallery widgets, for example) (Figure 2 uses a ListView widget);
Another widget you may use is Dialog. It is used to display the detail of a hotel
after clicking one list in the ListView. There is also a built-in widget (RatingBar)
for you to display ratings.
After clicking the Post to Facebook button the Facebook SDK dialog Post to Wall is
displayed, as shown in Figure 3.
Click on Downloads and select the Download .zip button. The ZIP file will be
downloaded to you PC or Mac. Extract the ZIP file on your Desktop. Name the folder
facebook-android-sdk.
With a text editor, open the file named README.md inside the facebook-android-sdk.
You will install the SDK and a sample program.
Use the instructions in the README.md file to install and configure the Facebook SDK,
as described in the section titled Getting Started, which is duplicated here:
Create a new project for the Facebook SDK in your Eclipse workspace.
Open the File menu, select New --> Project and choose Android Project (inside
the Android folder), then click Next.
Select "Create project from existing source".
Select the facebook subdirectory from within the git repository.
You should see the project properties populated (you might want to change the
project name to something like "FacebookSDK").
5
Build the project: from the Project menu, select "Build Project". You may see a
build error about missing "gen" files, but this should go away when you build the
project -- if you have trouble, try running "Clean..." in the Project menu.
Run the application: from the Run menu, select "Run Configurations...". Under
Android Application, you can create a new run configuration: give it a name and
select the simple Example project; use the default activity Launch Action. See
http://developer.android.com/guide/developing/eclipse-adt.html#RunConfig for
more details.
If you did all the above correctly, you will now have a running Android application with
a login UI as displayed in Figure 4 below.
The Login/Logout button remains the same, with identical behavior as in the
sample.
Instead of the four buttons, you should display a text field, a spinner and a search
button just like the interface in HW #8.
When a button named "Search" is clicked, the JSON data from HW #8 (from
Tomcat) is retrieved.
8
Data about the hotels is displayed, and the UI allows selecting one of the list
items.
Post to the user's Facebook Wall an introduction containing the hotel name,
location, rating and review link to tripadvisor.com, using the Facebook SDK for
Android.
Facebook offers multiple APIs for you to upload or request data. In this
implementation, you can use the Graph or REST APIs.
For the Graph API, please check the document here:
http://developers.facebook.com/docs/reference/api/
For the REST API, please check the document here:
http://developers.facebook.com/docs/reference/rest/
The suggested size of your image thumbnails in your list view of your Android
user interface is (100, 100).
If you still have problem on creating projects with Facebook API following the
above instructions, you can create a new project and copy all the source code and
resource file from Facebook API and sample projects to your new project. Make
sure that you eliminate all the compiling errors and then start creating your own
activities, so that you can use all the classes in the Facebook API freely.
You are supposed to handle such situations like no hotels found and inform user
whether the posting to the wall is successful or not.
To better understand how Facebook Feeds work, you can read this page:
http://wiki.developers.facebook.com/index.php/Feed
5. Prerequisites
This homework requires the use of the following components:
Download and install Eclipse. Download and install the Android SDK.
Instructions on how to download and install both are available on the class
website at http://www-scf.usc.edu/~csci571/2011Spring/eclipse_setup_v6_9.pdf.
2. You need to create a Facebook Platform application as documented at:
https://developers.facebook.com/docs/mobile/android/build/#register. To do that
you will need to create a Facebook Developer application: go to
https://www.facebook.com/developers/createapp.php and click Allow it to access
your information. Then click Set Up New Application. Name the application,
agree to the terms, and click on Create Application. In the following windows
keep all the defaults and click Save Changes. See the sections Creating Your
Facebook Application and Configuring Basic Settings. In the window that
displays next, you should see the Application ID (see figure below) that you will
have to use with the Android Facebook SDK.
1.
10