Use Motion Sensors in your Android Application.

screen shot of motion application

Motion App

This article goes over the basics of using the Android motion sensing APIs. For simple applications you might want to use motion sensing to turn features like sounds or settings on and off. For more complex applications like games you can control complex movements of on screen objects. Controlling movements requires not only the motion sensing APIs but also a good understanding of how the numbers returned by the APIs

change and of the physics related to the objects you are controlling. These are complex topics which we will not be covering in this article.

The Example Application

The application shows an image whenever it senses that the device has moved. There is a button that can be used to enable/disable the motion sensor. (The image used in the app is  the Android application icon that is included with all new projects created in Eclipse.)

The API

Our application uses the Accelerometer. The API functions through a listener. When motion is detected the device calls the listener and passes data representing that motion. The data is in the form of a three element array. The three elements correspond to acceleration along the three axis X, Y and Z. Your application has to implement the listener. The listener is where you put code that you want to respond when motion occurs. In our app we check how much the values have changed since the last call to the listener. If they have changed only a little we ignore it. If they have changed more than a little we conclude that the device has moved and we do something (ie. show an image).

The code in our listener looks like this:

/* WITH COMMENTS */
// check each of the three Axis
for (int i = 0; i < event.values.length; i++) {
    // calc diff with value recorded on last pass
    float diff = Math.abs(event.values[i] - last_values[i]);
    // ignore small differences
    if(diff > (last_values[i]*SENSITIVITY)){
        // show the image
        ifImage.setVisibility(View.VISIBLE);
        // image will be cleared after set amount of time
        last_time_moved = System.currentTimeMillis();
    }
}
// save current values to last_values
/* WITHOUT COMMENTS */
for (int i = 0; i < event.values.length; i++) {
    float diff = Math.abs(event.values[i] - last_values[i]);
    if(diff > (last_values[i]*SENSITIVITY)){
        ifImage.setVisibility(View.VISIBLE);
        last_time_moved = System.currentTimeMillis();
    }
}

Getting Android to Listen

Having created a listener we then have to tell Android to use it. The methods on listeners are only called after they have been registered. Being a “SensorListener” ours needs to be registered with the SensorManager. From inside of an Activity we can get a reference to the SensorManager like this:
Sensor Manager sensor_manager =
(SensorManager)getSystemService(SENSOR_SERVICE);
This is typically done from within the Activity’s “onCreate()” method.
The listener is then registered using a “registerListener()” method call like this:
// register
sensor_manager.registerListener(
(SensorEventListener)MPMotionSensorActivity.this,
sensor,
SensorManager.SENSOR_DELAY_NORMAL);
The parameters here bear some mention. The first one points to an instance of the current activity which is cast to the sensor listener type. It is common, like is being done here, to have the current activity implement the listener interface. To do this we just add “implements  SensorEventListener” to the class signature and then add the interface methods to the class itself.
The second parameter “sensor” represents the sensor we are planning to listen to. In this case we are listening to the accelerometer. We need to get an instance of the sensor to pass here and that is done like this:
sensor = sensor_manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
This is done in the “onCreate()” method right after the line where we get the sensor manager. The third parameter is a constant that determines how often we want the system to poll the sensor.

Where to Listen

We will be registering the listener in two places. First we will register it when the user clicks and changes the button from unchecked to checked We will also register it in onResume(). In that case we will only register it if the button state is “checked”.

Only Listen When Necessary

For this app we only want to listen when the app is in the foreground. That means that when the app is paused we will no longer need to check if the device is being moved. It is good practice to unregister the listener in these cases. We can do that in the “onPause()” method like this:
sensor_manager.unregisterListener(
(SensorEventListener)this, sensor);

Thats all there is to using sensors in Android. You can download the Activity and Layout files from here > AndroidMotionApp <

MarkP

References

Android Developer’s Reference on Sensors
http://developer.android.com/guide/topics/sensors/sensors_motion.html

Discussion of Event Data for Various Sensors
http://developer.android.com/reference/android/hardware/SensorEvent.html

 

Things to consider before starting mobile development: iOS vs. Android

There are two types of software that currently dominate the mobile App market. iOS (Apple’s operating system, which includes iPhones, iPads, iPods) and Android (Google’s Linux based operating systemwhich includes all Android powered phones and tablets, the HTC, Droid, Samsung Galaxy etc.) These two operating systems will continue to coexist, and it is worth knowing their differences before starting mobile application development. Both of these platforms have a number of positives and negatives that each developer should consider.

iOS

iOS is the operating system that both the iPhone and iPad run on and both of these are among the most popular products in their respective markets. The iPhone is the most popular smartphone and the iPad is one of the highest selling tablets. Both of these products have the highest profile, and are viewed as the best brand and best standard. The design, quality, and user experience for iOS apps are all considered to be superior than those of Android apps. iOS application development is a uniform system, and each application is consistent. Those who are less tech-savvy generally choose iOS. iOS also currently has the most applications available, and the App store has methods for quality control.

However products that run on iOS, the iPhone and iPad, are generally more expensive. Also iOS applications can only be developed on a Mac. The standardization makes it difficult to customize each application and there are less developers who are familiar with the objective-C language that iOS apps are written in.

Android

There are more people who use the various tablets and smartphones that run on the Android system. Since there are more sellers in the Android market, Android products tend to be less expensive than Apple products and this is what leads to the greater number of Android users. While iOS application development is more rigid, Android development gives more freedom. Android applications can be developed in Windows, Mac, or Linux, and there are more developers who understand Java, which is used to develop Android apps. Also, Android is more commonly chosen by businesses since it is more customizable and can be locked down.

While Android has these benefits, its user experience is not as good as iOS. The lack of consistency makes it more difficult for support for Android devices and the quality control in the iOS app market is much better than that in the Android market.

 

A handful of HTML5 frameworks

For those of you who are just starting to get into HTML5/CSS3 there are a bewildering number of frameworks to choose from including everything from resets and starter templates to full blown object oriented JavaScript libraries. The list below gives just a taste of what ‘s available as you begin your search for the promised land in the world of web development.

52Framework
A simple lightweight html5/css semantic tag template, minimal javascript mainly to assist formatting
Main Site: http://52framework.com/
Demo page, shows many HTML5 and CSS3 features in-use: http://demo.52framework.com/demos/html5/full.html
Article on basics: http://designshack.net/articles/css/52-framework-the-first-ever-html5-and-css3-framework

HTML5Boilerplate
A foundation framework that fixes many cross-browser issues, it is designed to be transparent (use it to start off then forget its there)
Main Site: http://html5boilerplate.com/
Alternative: HTML5Reset, Both frameworks include CSS reset features

Modernizer
HTML5 feature detection framework, among other things it can be used with media queries to branch CSS and make a site work with older browsers
Main Site: http://www.modernizr.com/
Article: showing how you can use the framework: http://www.alistapart.com/articles/taking-advantage-of-html5-and-css3-with-modernizr/

SproutCore
An HTML5/JavaScript framework that can be used to create full application-like web sites, adds full MVC and object orientation to JS
Main Site: http://sproutcore.com/
Demo: shows just how much can be done with this framework, (for guest login email not required) http://tasks.sproutcore.com/

QooXDoo
An HTML5 framework that targets application-centric web development for desktops, also has features for mobile dev
MainSite: http://qooxdoo.org/
Nice widget demo site: http://demo.qooxdoo.org/current/widgetbrowser/
Demo Sites: that show the framework’s many features in-use: http://demo.qooxdoo.org/current/demobrowser/#
Try-it-out site: very cool site that lets you play with code and see results at the same time: http://demo.qooxdoo.org/current/playground/#Hello%20World-ria

 

iPhone and Android App Developers – How Many Hats can You wear

 

Developers looking to become successful with Apps should know that there is much more to it than just programming. If you want people to use your app there are a lot of steps involved that have nothing to do with the coding background or skills you already have.

Learning the platform
Despite what you might think mobile development platforms are not the same as their desktop counterparts. Apple’s Cocoa Touch adds many device specific features to Object C Projects. The Android OS could kill your app at any time if you don’t know about and learn to code for its unique application lifecycle and background processes model.

Look and Feel
The skills that make someone a good programmer do not necessarily make them a good interface designer or graphic artist. When it comes to apps users the vast majority of users go for, good looking, easy to use and free. Making good looking apps requires an eye for color and layout as well as skill in creating button, background and control graphics. For example look at … it has a custom … and … which make it hard to put down.

Pre-flight
Once the app is created it needs to be tested. A buggy app will not only get installed but will also inspire negative comments to be posted to the market where you’ve made it available be that the AppStore, Android market or the slew of other smaller markets. Self contained apps, those that do not require network connections or pull data from the internet may not be so hard to test. But what are the chances of your app fitting this profile? After all the value added by users being able to interact with other users, upgrade features, download information and other network related activities make for compelling experiences. For networked apps you should really do testing that uncovers problems with lost connections, slow connections, failed downloads, server loading problems and other issues. For this you will need a bunch of users, preferably ones who will not complain publicly about the problems they encounter as they help you get your app ready for prime time.

 

Launching
You might think that uploading the app to the market would be the simplest task but there are requirements here too. First you will need to produce graphics such as app icons, promotional banners and screen shots to use when filling out the upload form. These then become the public face of your app and are seen when people look at your app in the market. In addition to these graphics you will need a full description of the purpose, utility, features, advantages, etc. that will be read by prospective users. If you are not used to writing technical or marketing material this can become much harder than it seems and you will come to appreciate the work put in by other app developers to make their app descriptions interesting and compelling.

 

Post-Launch
So now you think you are going to sit back, watch the downloads roll in, and plan those cool new features you weren’t able to get to the first time around. Think again. At this point you will need to keep an eye on downloads, uninstalls, comments, competitors, their updates and new features and, if you are displaying ads in your app, click rates for those ads. Your app can easily be ignored and see few downloads if even a few of the early users give negative comments. As your app gains in popularity you will want to know how many people have downloaded your app and how many decided to uninstall it. The ones who install and don’t uninstall are your core users. If you’ve decided to offer a free “intro” app and a similar but full featured paid app you will notice a huge difference in download rates between the two with the free app leading by a wide margin. You may find that many users don’t but the full featured version because you’ve done too good a job with the free app. Or the free app may be so lacking in features that it discourages people from buying your paid app. All of these are marketing issues typically handled by a product manager not a programmer.

What to do
Well you may be one of those rare individuals who can take on all these varied tasks and do each one well. But if you are like the rest of us, and you are realistic, you will come to see this as a good time to get some help. Either spend some time learning these skills or find people who already do these things and ask them to help out. If your app is interesting it may be easy to get people excited enough to want to participate in its production and promotion. Friends and co-workers are a good place to start.


One Rockin’ Stereo Bluetooth Headset – The Samsung HM3700 Stream Liner

The bluetooth headset Unit itself

The Unit

I’ve been using the Samsung HM3700 bluetooth headset for a few weeks now and its really been working for me. With its stereo capabilities and many configuration options it comes in handy in situations you may never have thought of to use a bluetooth headset. Because its bluetooth I can connect it to my many computers, smartphones and tablets. Because it’s stereo…

Continue reading