Pressure is a float from 0 to 1. What it means is hardware-dependent. Even if there is a hardware pressure sensor, the map between the actual force and the return value of getPressure()
still depends on the device. Also, some devices without a hardware pressure sensor simulate pressure from the size of the touch point, that is, they are assuming that more pressure means your finger flattens out. Other devices just return a constant value.
Also, force or weight (measured in Newtons) is not the same as mass (measured in grams). See http://en.wikipedia.org/wiki/Mass_versus_weight.
If you want help with your exception then you should post the source and the line where it is thrown. adb log
is your friend.
EDIT:
You use pressure uninitialized. Its just declared but not set to anything, so it is null
. Calling one of its methods is a NullPointerException. Only View
s (widgets) can receive MotionEvent
s. You need to do something with your activity (e.g. inflate a layout) and then set a touch listener to one of the views of the layout:
someView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float pressure = event.getPressure();
}
});