I'll try to approach this from a physics standpoint rather than an Android/programming standpoint:
Let's say the TYPE_GRAVITY
sensor returns a vector G = [xG, yG, zG].
The TYPE_LINEAR_ACCELERATION
sensor returns another vector A = [xA, yA, zA].
What you're looking for is the magnitude of the projection of A onto a unit vector in the direction of G. In other words, how much of A is in the direction of G?
First we need to get the unit vector in the direction of G, which we'll call Gunit (see what I did there?). To get this, we divide each component of G by its magnitude ||G||, where ||G|| is the square root of the sum of the squares of each component (the distance formula). Thus,
Gunit = [xG / ||G||, yG / ||G||, zG / ||G||]
The magnitude of the component of A in the direction of G is then given by computing the dot product:
A · Gunit = (xA * (xG / ||G||)) + (yA * (yG / ||G||)) + (zA * (zG / ||G||)).
The result is a scalar (not a vector), and that's the quantity you're looking for.
Here's a good wikipedia article for reference: http://en.wikipedia.org/wiki/Vector_projection