Backported Android Java code to work with 2.6