Almost inevitably hitherto unnoticed bugs will appear once an app runs on a real device. Among the many possible causes for unexpected behaviour is forgetting to change localhost references to the real server on the web! To automatically deal with this one needs to find out if running on a device or emulator, which seems essential in many ways but strangely is nowhere documented.
import android.os.Build;
public static final boolean isEmulator(){
return Build.MODEL.equals("sdk");
}
The android.os.Build class holds all kinds of information about the platform we're running on. I picked the MODEL field, which gives me "sdk" on the emulator and "HTC Magic" on the phone, but you might replace that with whatever you see fit.
No comments:
Post a Comment