开发者

android- How to differentiate the Emulator and Device Programatically

In My application one button is there. if you click on that button we are getting current Location. Based on this current Location i am doing some operations. In device it is working properly. But in emulator we are not getting the current Location thats why i am using the Some default Latitude and Longitude values for emulator. But i want to differentiate the emulator and device. It means we are running in the device means it takes the geocode locatio开发者_如何学编程ns. suppose we are running in the emulator means it takes the default latitude and longitude values. How to implement it pro-grammatically. can anybody help me.

thanks


See http://commonsware.com/blog/Android/2010/05/27/identifying-emulator-android-2.2.html.

Say Thank you, @CommonsWare.


I had exactly the same problem with the digital compass. I have solved it by writing and using the method below:

public static boolean areOrientationSensorsAvailable(Context ctx) {
    final SensorManager manager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
    final List<Sensor> sensorsMagnet = manager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
    final List<Sensor> sensorsAccel  = manager.getSensorList(Sensor.TYPE_ACCELEROMETER);

    return (sensorsMagnet.size() != 0) && (sensorsAccel.size() != 0);
}

This would work for you as well: if there's no sensor you are on the emulator. This is not "clean" (not suitable for a released application I mean) but this is fine for testing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜