1

The 'Moto E' devices do not have magnetic field sensors. Yet they seem to emulate it using GPS. But of course that only really works if you are moving. I would prefer to know that it is doing that, so I could disable some functions, or warn the user.

I can't seem to find a way of doing it like you can with many other devices, because the sensor 'exists' even if emulated.

For that matter, this model also has no gyroscope. Yet FusedSensors seem to work pretty well (although maybe not as well as on other devices).

Thanks for any input! Dave

Dave Hubbard
  • 469
  • 5
  • 11
  • "The 'Moto E' devices do not have magnetic field sensors" -- seriously? "because the sensor 'exists' even if emulated" -- what specific sensor are you looking for? And what specific Moto E is this? – CommonsWare Aug 24 '16 at 19:16
  • Moto E 2nd Gen. I just want to detect if it has a real 'Sensor.TYPE_MAGNETIC_FIELD'. See Motorola's specs at [link](http://www.motorola.com/we/products/moto-e-gen-2) . Versus, say, a Droid model, see [link](http://www.motorola.com/us/products/moto-z-droid-edition) . An owner of a Moto E reported that my navigation app, if you are not moving, shows 0 as the compass reading. Has had this issue with other apps like 'GPS Essentials' as well. – Dave Hubbard Aug 25 '16 at 00:00
  • Just tried this: '' in the manifest. It does not break anything on my device (which has a compass) or on the emulator, which does not give an option for including or not including a compass. I sent it to my tester with the Moto E. We'll see if the 'emulated' compass counts or not. – Dave Hubbard Aug 25 '16 at 01:15

1 Answers1

2

The idea of using: <uses-feature android:name="android.hardware.sensor.compass" android:required="true" />

in the manifest did not seem to have any effect at all.

However the following code did in fact work!

PackageManager manager = getPackageManager();
boolean hasCompass = manager.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
if (!hasCompass)
{
    Toast toast = Toast.makeText(this, "WARNING: DEVICE HAS NO COMPASS", Toast.LENGTH_LONG);
    toast.show();
}

I want to give credit for this to pointtofuture in the post [question]: How to make sure an android device application supports hardware feature

I should note that I tried this on the 'Moto E 2nd Gen' (No compass), and a Samsung Galaxy S7 Edge (has compass) and it was consistent. The AndroidStudio emulators all showed as having a compass, but the emulator setup does not allow selection or de-selection of that hardware feature (It does for GPS and some others). It would be nice if the emulators had compass emulation.

Dave

Community
  • 1
  • 1
Dave Hubbard
  • 469
  • 5
  • 11
  • Nice bit of analysis! That being said, I would not rely upon all manufacturers who offer faked `TYPE_MAGNETIC_FIELD` sensors to be nice and say they do not have the compass feature. I am not quite certain how this device passed Google Play compatibility testing, as the Compatibility Definition Document for Android 5.0 (and higher) has "MUST accurately report the presence or absence of sensors per the android.content.pm.PackageManager class" and "MUST return an accurate list of supported sensors via the SensorManager.getSensorList() and similar methods", and the latter is violated here. – CommonsWare Aug 25 '16 at 19:29
  • What is interesting is that at least on the Moto E, the PackageManager correctly says there is no compass. Yet, you can register a listener for TYPE_MAGNETIC_FIELD Sensor events. Since the Moto E is not mine, I can't easily tell if it is getting events. Although the owner told me that other compass apps do respond, sort of. I might ask him to test a debug version with an event counter. – Dave Hubbard Aug 25 '16 at 19:49
  • "The idea of using `uses-feature`... in the manifest did not seem to have any effect at all" -- this is not checked when installing the app over `adb`, including deploying from an IDE. So, I would not rule this out. I picked up one of these, and when I dump the list of available sensors via `getSensorList(Sensor.TYPE_ALL)` on `SensorManager`, I don't see a magnetic field sensor show up. And when I call `getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)`, I get `null`. So, AFAICT, this device is behaving properly. – CommonsWare Sep 01 '16 at 19:01
  • 1
    I found that 'uses-feature' is used to determine which devices are compatible on Google Play. When I set the compass to be required, the list of compatible devices dropped almost in half. So I just left it as being used but not required, and adapted my app to not support features that required it, and warn the user about other things that had reduced functionality. – Dave Hubbard Sep 03 '16 at 01:21