Proximity sensor tweek to give you Samsung galaxy s4 airwave feature

16 Aug

The recently released samsung galaxy s4 phone comes with some interesting features. This will be a look at how you can emulate the airwave feature on any ordinary android phone.

proximity-callThe proximity sensor is common on most smart-phones. This is because the primary function of a proximity sensor is to disable accidental touch events. The most common scenario being- The ear coming in contact with the screen and generating touch events, To solve this issue, device manufacturers came up with the idea of a placing a proximity sensor close to the speaker, which will then detect any object in the vicinity of the speaker.while on a call. We can use this to detect gestures made by user. The technology behind it is pretty neat and can be found by googling around.

The code below will allow one to detect when a user swipes across the phone without touching the screen, as soon as that event is registered the list view will scroll.

Lets start with the layout, place a list view on the layout:

<RelativeLayout xmlns:android=""
 tools:context=".MainActivity" >

 android:layout_alignParentTop="true" >


And then inflate that layout on the java end. And place the following code

package com.example.proximity;

import java.util.ArrayList;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

SensorManager mSensorManager;
 Sensor mproximity;

 ArrayList<String> items = new ArrayList<String>();

 protected void onCreate(Bundle savedInstanceState) {

 //populate the arraylist
 for(int i = 0; i< 100; i++ ){
 items.add("Item " + i);

 final ListView list = (ListView) findViewById(;
 list.setAdapter(new ArrayAdapter<String>(this,
 android.R.layout.simple_list_item_1, items));

 //Access the sensor manager
 mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
 mproximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

//register a listener for the proximity sensor
 SensorEventListener proximityListener = new SensorEventListener() {

 //Incase of a gesture scroll the list
 public void onSensorChanged(SensorEvent event) {
 // TODO Auto-generated method stub
 list.smoothScrollBy(200, 1000);

 public void onAccuracyChanged(Sensor sensor, int accuracy) {
 // TODO Auto-generated method stub






There are no permissions needed.


This is just some basic implementation which has a lot of short comings, but with a few tweeks can bring up amazing features. You are welcomed to use the code and modify it.



Posted by on August 16, 2013 in Uncategorized


7 responses to “Proximity sensor tweek to give you Samsung galaxy s4 airwave feature

  1. John F.F.L. Freitas (@jfflfreitas)

    September 6, 2013 at 2:52 pm

    Hello, First, nice tutorial!! according to the tutorial, the list scrolls down only when the sensor detects my hand, I can do so more as back up when I do the opposite movement of my hand?

    • Gilbert Kimutai

      September 6, 2013 at 3:34 pm

      What I had in mind is define a different gesture for that say moving the hand twice in succession. This can be achived by starting a timer and some simple logic. The sensor detects both motions – forward and backward movement of the hand – as being the same. Thats my idea if you have a simpler way please share.

      • John F.F.L. Freitas (@jfflfreitas)

        September 6, 2013 at 6:23 pm

        My goal is to make an image gallery slider air gesture similar to the Samsung using the proximity sensor, but I’m not getting!
        I want according to the movement of my hand to the left or right, the photos in the gallery move. how can I do this?

  2. John F.F.L. Freitas (@jfflfreitas)

    September 6, 2013 at 6:23 pm

    Meu Objetivo é fazer uma galeria de imagens deslizante semelhante ao air gesture da samsung utilizando o sensor de proximidade, porém não estou conseguindo!
    Quero que de acordo com o movimento da minha mão para a esquerda ou para a direita, as fotos na galeria de imagens se movam. como posso fazer isso?

  3. アバクロ 通販

    September 11, 2013 at 9:46 am


    • Gilbert Kimutai

      September 11, 2013 at 10:12 am



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: