Using Android to Launch Mobile Learning Content [Techie]
In this blog, I am taking a turn in the techie direction. As I am preparing to teach an Android programming class in the Spring of 2011 I have been creating some test apps to learn the Google Android API’s. I am not going to spend any time on how to set up the Eclipse for Android programming (use this link for that) or how to program in Java (also a lot of resources on that). There are a whole host of videos on YouTube or other sites on programming with Google Android and Java. Most of what you get in this post is a source code template to use (if anyone has suggestions to make it better, send them along).
_______________________________________________________________________________
The Launcher App
One of the apps I see a lot of on mobile devices are launcher apps which provide a button icon (see Red School House on image below) on the desktop designed to navigate to a web page for more information. The launcher app is simple and it leverages information already available on the Internet (thus saving development time) and simply provides a app launch link in to URL.
When one of the buttons is pressed, the application takes you to an Internet page opened in the browser. This page was formatted using MLEX but the Android browser has defaulted to a more aggressive formatting of the screen which has the effect of shrinking the test. It can easily be make bigger.
_______________________________________________________________________________
The Code
Pretty standard stuff from a Java programming standpoint. Package and import sections are straight forward. With Android, we work with activities (think of this as a screen) and intents (this of this as a request to do something – like go to the browser). We also have the Android Manfest and I have included the xml file that defines the main screen and string resources.
Starter.java
If you look at the OnCreate method you will see if opens the activity and sets the screen layout (called main and listed below). There are button events for each of the buttons that open the browser activity with a designated url.
package com.garymarrer.cis159mobile;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
//import android.widget.TextView;
public class Starter extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.main );
// Btn 1
Button link1Btn = (Button)findViewById( R.id.link1_btn );
link1Btn.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
Uri uri = Uri.parse( “http://www.garymarrer.com/facsite/Default.aspx” );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
});
// Btn 2
Button link2Btn = (Button)findViewById( R.id.link2_btn );
link2Btn.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
Uri uri = Uri.parse( “http://www.garymarrer.com/facsite/cis159.aspx” );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
});
// Btn 3
Button link3Btn = (Button)findViewById( R.id.link3_btn );
link3Btn.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
Uri uri = Uri.parse( “http://www.garymarrer.com/facsite/links.aspx” );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
});
// Btn Exit
Button exitBtn = (Button)findViewById( R.id.exit_btn );
exitBtn.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
System.exit(0);
}
});
}
}
_______________________________________________________________________________
Android Manifest
The manifest handles permissions and setting but most importantly the name of the activity used for the main screen.
<?xml version=“1.0″ encoding=“utf-8″?>
<manifest xmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.garymarrer.cis159mobile”
android:versionCode=“1″
android:versionName=“1.0″>
<application android:label=“@string/app_name” android:icon=“@drawable/school”>
<activity android:name=“.starter”
android:label=“@string/app_name”>
<intent-filter>
<action android:name=“android.intent.action.MAIN” />
<category android:name=“android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion=“6″ />
</manifest>
Main.xml
This xml file holds the screen definition.
<?xml version=“1.0″ encoding=“utf-8″?>
<!– Gary
Marrer
Android Project
–>
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:orientation=“vertical”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:background=“#000000″
android:gravity=“center”
android:padding=“7dip”>
<TextView
android:id=“@+id/view_Line2″
android:cursorVisible=“false”
android:text=“CIS159 Mobile”
android:textSize=“20px”
android:layout_width=“fill_parent”
android:gravity=“center”
android:layout_height=“50px”
android:textStyle=“bold”/>
<ImageView
android:id=“@+id/pic_view”
android:layout_width=“fill_parent”
android:layout_height=“125px”
android:src=“@drawable/school”
android:layout_below=“@id/view_Line2″/>
<TextView
android:id=“@+id/view_Line3″
android:text=” “
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:layout_below=“@id/pic_view”/>
<TableLayout
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:layout_weight=“1″
android:layout_below=“@id/view_Line3″>
<TableRow
android:layout_weight=“1″
android:gravity=“center”>
<Button
android:id=“@+id/link1_btn”
android:layout_height=“fill_parent”
android:layout_width=“0dip”
android:gravity=“center”
android:text=“GCC Faculty Web Page”/>
</TableRow>
<TableRow
android:layout_weight=“1″
android:gravity=“center”>
<Button
android:id=“@+id/link2_btn”
android:layout_height=“fill_parent”
android:layout_width=“fill_parent”
android:gravity=“center”
android:text=“CIS159 Syllabus”/>
</TableRow>
<TableRow
android:layout_weight=“1″
android:gravity=“center”>
<Button
android:id=“@+id/link3_btn”
android:layout_height=“fill_parent”
android:layout_width=“fill_parent”
android:gravity=“center”
android:text=“Class Links”/>
</TableRow>
<TableRow
android:layout_weight=“1″
android:gravity=“center”>
<Button
android:id=“@+id/exit_btn”
android:layout_height=“fill_parent”
android:layout_width=“fill_parent”
android:gravity=“center”
android:text=“Exit”/>
</TableRow>
</TableLayout>
</RelativeLayout>
String Resources
<?xml version=“1.0″ encoding=“utf-8″?>
<resources>
<string name=“hello”>Hello World, starter!</string>
<string name=“app_name”>GCC CIS159</string>
</resources>
All of the source is here but if you want to download and test on your Android (As always, use at your own risk..). You can Save as this link: http://www.garymarrer.com/android/cis159mobile.apk
Comments?
_______________________________________________________________________________

In: Android, Techie Stuff, Using Mobile Tech, techie





