code tested for android, it works.