Samsung phone runs Android operating System and HTC phone runs Android operating system (Assuming both Samsung and HTC phone have accelerometer sensor).
Can I use same Java code, which have been written for accessing data from accelerometer sensor on Samsung phone, for accessing data from accelerometer on Motorola phone?
Of course you can (and you should) use the same API, the hardware Android API.