hemanthrajv / flutter_compass

MIT License
102 stars 188 forks source link

java.lang.IllegalStateException: sensorManager.getDefaultSensor(sensorType) must not be null in Flutter #27

Closed mohammednabil95 closed 3 years ago

mohammednabil95 commented 4 years ago

I have build a flutter app which has features like showing qibla direction with the help of flutter_compass dependencies. This App works fine in newest versions of Android Devices but if i try to install this app in older versions (API 16, API 17) it shows "Unfortunately this App has Stopped". I checked in logcat it shows "java.lang.IllegalStateException: sensorManager.getDefaultSensor(sensorType) must not be null". So do i need to add some native code in android folder or dependencies in buildgradle ?

medyas commented 4 years ago

@mohammednabil95 You should probably first check whether the devices has the sensor hardware, and this is what causing your crashes as the device does not have any hardware and your trying to access it anyway.

medyas commented 4 years ago

@mohammednabil95 checkout this package which i developed flutter_qiblah Its has a method which allows you to check whether the device has the required hardware: final _deviceSupport = FlutterQiblah.androidDeviceSensorSupport();

ebjerkelund commented 3 years ago

I have a similar issue on a Samsung 5.1.1 device. Other compass apps work fine.

Related to #39 ? The compass apps that do work are using Sensor.TYPE_ACCELEROMETER and Sensor.TYPE_MAGNETIC_FIELD

hemanthrajv commented 3 years ago

Fixed by #62