Is there a function (or variable) that I can test to see if the app is running on the emulator vs. on the real hardware?

Or is there a better way to do testing on the emulator for code that uses hardware that's not available on the emulator?