Thursday, November 20, 2014

New Sensors in Android 5.0 (Lollipop)

I found a few non-documented sensors on Lollipop (Android 5.0) on a Nexus 5.

Tried looking for them, but could't find any documentation on them on. Looks like they are mostly software sensors.

Android app on Google PlayHere's the list that I have found. I have written a simple app that displays all the sensors and shows there values. Not to mention that, only for the ones that are documented. For the ones not documented, you can only see it's details.

There are only a few which appear on developer.android.com.
Here's an excerpt from the announcement.

New types of sensors

In Android 5.0, a new tilt detector sensor helps improve activity recognition on supported devices, and a heart rate sensor reports the heart rate of the person touching the device.
New interaction composite sensors are now available to detect special interactions such as a wake up gesture, a pick upgesture, and a glance gesture.

Since there's no documentation, for some of them, I don't really know what they do. The only thing that gives you a clue is the sensor name. And, I don't know how to work with them as well.


Tilt Detector


AMD Sensor (No idea, whats that)


RMD Sensor (No idea, whats that)


Basic Gestures Sensor


Tap Sensor


Facing Sensor


Tilt Sensor


Pedometer


Pedestrian Activity Monitor

Update: Seems, the documentation is coming soon. XDA picked this up.


Friday, June 20, 2014

Easy Swipe to Refresh in Android

Swipe to Refresh Android
Recently, Google released a new version of the Support Library, which has an interesting component. It's called SwipeRefreshLayout. With that, it's become a child's play to implement a quick Swipe-to-Refresh control for your apps.

A few things first

  1. Available only with android-support-v13. Which means that only apps target SDK level 13 and above can use this.
  2. It can only contain one scrollable direct child such as a ListView or a ScrollView.
That's all you need to know. Well.. A few things more, basically some xml and java code.

For this example, we use a ListView with some demo data. Once the list view is scrolled, we do some task, wait for sometime, and update the list view's adapter. Finally, ask the SwipeRefreshLayout to stop the progress indicator, since we are done with refreshing.

The layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${packageName}.${activityClass}" >
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
The UI initialization
private void initializeViews() {
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
refreshLayout.setOnRefreshListener(this);
                // The default colors for the progress bar are not so nice.
setColorSchemeForProgressBar();
ListView listView = (ListView) findViewById(R.id.listView);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
adapter.addAll(getDemoData(5));
listView.setAdapter(adapter);
  }
The Refresh Task
       @Override
public void onRefresh() {
Log.i(TAG, "Refresh Requested");
doRefresh();
}
// Fetch data and update listview's adapter
private void doRefresh() {
RefreshTask task = new RefreshTask();
task.execute((Void) null);
The Completion Work
private void postRefreshComplete() {
// Stop the refresh animation
refreshLayout.setRefreshing(false);
// Update adapter with new data
adapter.clear();
adapter.addAll(getDemoData(new Random().nextInt(20)));
adapter.notifyDataSetChanged();
   }

And there you go, a simple swipe to refresh usage for your Android apps. You can find the whole source code here

Monday, March 31, 2014

Step Detector and Step Counter Sensors on Android

Android KitKat has added a few more hardware sensors to it's API list. Step Sensors are one of them, which looks very promising. Although, not a lot of phones yet have these Step Sensors, in the future, this would gradually become a standard I think. Currently, Nexus 5 has them.

Let's see how we can interact with these sensors. Basically, there are 2 sensors.
  1. Step Counter: This keeps a count of the number of steps that you have taken. The counter is only reset when you re-boot the device, else, for every step you take (or the phone thinks you took, you counts up).
  2. Step Detector: This sensor just detects when you take a step. That's it. 
The example project shows you how to initialize and setup the SensorManager and respond to events from the Sensors.
// Step Counter
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float steps = event.values[0];
textViewStepCounter.setText((int) steps + "");
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
SensorManager.SENSOR_DELAY_UI);

// Step Detector
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
// Time is in nanoseconds, convert to millis
timestamp = event.timestamp / 1000000;
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR),
SensorManager.SENSOR_DELAY_UI); 

No special permissions are required.

Head over to Github to get the full source code.

Saturday, December 7, 2013

Smartphone Usage Statistics Highlight Its Importance In Our Lives

Smartphone Usage Statistics Highlight Its Importance In Our Lives

This Infographic is produced by Coupon Audit (provides Finish Line promo code) and Techdroid.Kbeanie

If you would like to add this inforgraphic on your website or blog, copy and paste the below code as given in the textbox.

Friday, September 27, 2013

Making your Android apps crash-proof

Image courtesy: Crittercism Website
Do you have an android app on the Play Store, and get lots of negative comments/feedback?


Most of the time, apps crash on the first interaction with the user. And that's the reason most users are frustrated of even downloading your app, and that's when most of the negative comments start pouring in.

Of course, you have to look for crashes everywhere in your app, but crashing on the first page itself, is a really really bad situation. When that happens, and the user leaves a bad comment, instead of sending you a support mail, you have no idea how to fix it. You have no idea about the user's device, and other important information that would help you in determining the problem, and fixing it. And if you continue having such a build even for a week on the store, that puts a dent on your overall app reviews. People generally look at the first few reviews, and make a decision based on that, whether to try your app or not.

I have had an app on the store for years now, which I didn't update for a long time. And finally, when I got the time to work on it again, I decided to integrate Crittercism SDK within my app, along with Google Analytics SDK.

The very first update with +Crittercism along with +Google Analytics , my inbox was flooded with crash reports. I was amazed at how many un-reported crashes my app had. I was living in the dark, as to what all problems users were having with my app. Crittercism logs had more information about the crashes than I could have asked for. They were pretty detailed, in terms of the user's device name, and OS versions, the version of the application, and a device snapshot (Memory/Storage) when the crash occurred.

After about a week, I made the next update, and this time, the crash notifications reduced dramatically, although the number of users and the average usage of my app went up. From this, I can guess that the users who are still using my app are a happy lot. And that makes me happy as well.

I would strongly recommend integrating such a live error reporting tool into your apps to get live feedback for your apps. Specifically for Crittercism, there are free and paid plans. Currently, I am on the free plan, and it gives me the almost everything that I need to know to fix those random crashes. With paid plans, you have more reporting, which I think I don't need right away. Receiving crash notifications is just the one part of Crittercism. They call this solution as a "Mobile Application Performance Management" solution. Rightly so?

Have you used Crittercism in your apps? Do you have anything to say?