# Android device with sensors does not call Java\_com\_epicgames\_ue4\_GameActivity\_nativeHandleSensorEvents method

**URL:** <https://forums.unrealengine.com/t/android-device-with-sensors-does-not-call-java-com-epicgames-ue4-gameactivity-nativehandlesensorevents-method/1327135>\
**Category:** Mobile\
**Tags:** unreal-engine, Android, question, CPP\
**Created:** [October 9, 2023, 1:16pm UTC](https://forums.unrealengine.com/t/android-device-with-sensors-does-not-call-java-com-epicgames-ue4-gameactivity-nativehandlesensorevents-method/1327135 "2023-10-09T13:16:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![c2170](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c2170](https://forums.unrealengine.com/u/c2170)\
**Post date:** [October 9, 2023, 1:16pm UTC](https://forums.unrealengine.com/t/android-device-with-sensors-does-not-call-java-com-epicgames-ue4-gameactivity-nativehandlesensorevents-method/1327135/1 "2023-10-09T13:16:32Z")

</div>

I have a Xiaomi Pad 6, which is an Android device with gyroscope, acceleration sensor, etc.

However, this device does not respond to gyroscopes in the game I am developing.  
I debugged with VS2022, and found that the breakpoint I set inside **Java\_com\_epicgames\_ue4\_GameActivity\_nativeHandleSensorEvents ( in AndroidJNI.cpp)** was never hit. So I guess that’s why the device cannot respond to any sensor change, even though it has some sensors.

I want to know why the function in engine is never called on certain device.

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![c2170](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c2170](https://forums.unrealengine.com/u/c2170)\
**Post date:** [October 10, 2023, 2:29am UTC](https://forums.unrealengine.com/t/android-device-with-sensors-does-not-call-java-com-epicgames-ue4-gameactivity-nativehandlesensorevents-method/1327135/2 "2023-10-10T02:29:12Z")

</div>

I debugged with Android java code in GameActivity.java, and found that it is because this device doesn’t have magnetometer. So that “onSensorChanged” function returned directly.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/5/bb5eab7af65ef254f2e91e6603f58ce83133d537.png)

Here’s my solution: I use GAME\_ROTATION\_VECTOR to calculate the rotation matrix instead of getRotationMatrix. Because this vector is a quaternion, which is easy to transform to rotation matrix.

Hope my experience can help someone 🙂

If you have some other idea, please share with me 😃

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 9, 2023, 2:29am UTC](https://forums.unrealengine.com/t/android-device-with-sensors-does-not-call-java-com-epicgames-ue4-gameactivity-nativehandlesensorevents-method/1327135/3 "2023-11-09T02:29:47Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
