No, it is not possible to find the gravity from the magnetometer.
What you are looking for is called sensor fusion. I have implemented sensor fusion for the Shimmer platform based on this manuscript, it's basically a tutorial:
Direction Cosine Matrix IMU: Theory
Another resource I highly recommend is Sensor fusion on Android devices.
But why are you doing it yourself? The SensorManager already offers what you want.