Using the Android Fragment API in a Tablet App

Since I got a new tablet running Android 4.0 aka ice cream sandwich I wanted to play around a bit with the fragments API and creating an application for a tablet. In the following tutorial, we’re going to build an application that renders several articles from a popular tech blog (just kidding) in a web view. What to build We’re going to build an application that is able to display web links in the left section of the screen and when clicked, displaying the corresponding website content in the right section of the application screen. ...

March 18, 2012 · 7 min · 1355 words · Micha Kops

Android Widget Tutorial: Creating a screen-lock Widget in a few steps

In today’s Android tutorial we’re going to take a look at Android’s Widget API and how to make a widget interact with a service using intents. Figure 1. hasCode Android Widget Tutorial Logo We’re going to create a fully functional application that allows us to enable or disable our smartphone’s screen lock settings using a widget that can be placed on our home screen. Finally, I am going to show how to use a smartphone to test and debug our application and connect it to the IDE. ...

October 6, 2011 · 10 min · 2082 words · Micha Kops

Sensor Fun: Location Based Services and GPS for Android

The Android SDK offers a nice API to receive information about available providers for location based services and get the current location and coordinates. In this short tutorial we’re going to build a small activity that displays a list of available location providers and shows the current position using GPS services. Example Application Create a new Android Project using ADT and your IDE with a package named com.hascode.android.location_app Add the permissions needed to the AndroidManifest.xml – it should look like this <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hascode.android.location_app" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".LocationActivity" 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="7" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission> </manifest> ...

May 30, 2010 · 4 min · 731 words · Micha Kops

First steps on Android: Creating a simple Todo App

In this tutorial we are going to build a simple todo app that is able to store simple todos in a database. The user is able to add new todos or delete old ones by clicking on a todo. For this tutorial we won’t use maven to keep it simple – if maven integration is desired – take a look at this tutorial. Steps Create a new android project using the Android SDK and your IDE Create some packages com.hascode.android.activity and com.hascode.android.persistence Create the layout in res/layout/main.xml – the main elements: a listview for the todos-list, a textbox and a button to enter new data. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/widget31" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <TableRow android:id="@+id/row" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/tasklist" android:layout_alignParentLeft="true" > <EditText android:id="@+id/etNewTask" android:layout_width="200px" android:layout_height="wrap_content" android:text="" android:textSize="18sp" > </EditText> <Button android:id="@+id/btNewTask" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+string/add_button_name" > </Button> </TableRow> <ListView android:id="@+id/tasklist" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" > </ListView> </RelativeLayout> ...

April 26, 2010 · 5 min · 1056 words · Micha Kops