Android Device Back Menu Opening Issue

I was working on word falling game where we have to type on keyboard different words.

When I was testing a game on Unity editor everything working fine but when I installed the game on actual android device, it was opening back menu panel.

For this, I have recorded a video so you can easily notice the problem - Please watch attached video:

Because of this game touch events, not able to work properly. I was getting touch down and up event call back issues because of this and my written code can’t able to work properly.

Please give me suggestion to sort out this problem for Android device.

NOTE: Keyboard is created with normal Key Sprites and Box Collider 2D attached to them.
Canvas UI not used in this.

Please some one help me into this, I got stuck

This is only a guess, but what you’re seeing is the effect of motion gestures, which are configurable in phone settings.

On other hand if application is consuming touch events, such motion gestures should be ignored.

Try modifying UnityPlayerActivity.java, specifically these method

    @Override public boolean onTouchEvent(MotionEvent event)          { return mUnityPlayer.getFrameLayout().onTouchEvent(event); }
    @Override public boolean onGenericMotionEvent(MotionEvent event)  { return mUnityPlayer.getFrameLayout().onGenericMotionEvent(event); }

to something like this

    @Override public boolean onTouchEvent(MotionEvent event)          { mUnityPlayer.getFrameLayout().onTouchEvent(event); return true; }
    @Override public boolean onGenericMotionEvent(MotionEvent event)  { mUnityPlayer.getFrameLayout().onGenericMotionEvent(event);  return true;}

that way your app would always consume touch events and not forward them to OS

1 Like

Still I have not installed within iPhone - May be this is happening because left and right edges of screen touches working as OS areas so it is opening menu items. Even from the edges swipes will create problem too.

Basically I have not installed Android Studio so it become difficult for me to export android project and use UnityPlayerActivity.java file.

Something like this kind of code, I found through ChatGPT - will this work?

void Start()
{
    #if UNITY_ANDROID && !UNITY_EDITOR
    // Disable swipe to open navigation bar or menu on Android devices
    int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    Window window = GetWindow();
    window.DecorView.SystemUiVisibility = (StatusBarVisibility)flags;
    #endif
}

that’s java code, you can’t put it into C#, if it would work, can’t say.

1 Like

But what to do sir? Already 2 days I spent with the similar problem.
For iOS this kind of code is working:

#if UNITY_IOS
        UnityEngine.iOS.Device.deferSystemGesturesMode = UnityEngine.iOS.SystemGestureDeferMode.All;
#endif

But what to do for Android? I hope, you have watched first post video link.

You can try putting that java code into some java file, put the java file in Unity project, the java file will be copied to gradle project.during the build

and then call the newly created java method via Unity - Scripting API: AndroidJavaObject.CallStatic from C#.

I would really recommend you to install Android Studio to make developing easier

If I export android project then I required to do complete build signing and export related process with Android Studio and within my life, I have not used this.

Wether a new input system can solve the problem? Then I am ready to try out that

This is a kind of common problem with new Android devices Because frequent touches opening menu bar of the phone.

You only need to use Android Studio temporarily, since it makes it easier to write code in java, once your java code is done, and you moved the java file into Unity project, you can get back to normal building from Unity.

Since it’s not clear what’s causing your problem, it’s not clear if it will help, but you’re welcome to try.

Please submit a bug with small repro project attached, so our QA can investigate. Thank you

Hello Sir, One thing, I have noticed that only this game project having issue with continuous touches and it is opening menu from top and bottom sides as like I have shown in the video.

I have created demo keyboard within another project and at their the same code worked fine.
Then after I have tried replacing ProjectSettings folder files with Demo Project ProjectSettings folder but result does not changed.

What to do now? Within Demo Project everything fine and I can’t able to trace the mistake from it.
Please help me if you can :slight_smile:

I am sorry, but it’s hard to say what’s wrong due many things which can I affect this kind of situation.

If you want, try reporting a bug with repro project attached, so our QA can look at it

Today I have spent few hours but I can’t able to solve the issue so I have submitted bug report to Unity.
At last I got message that I will get an email from Unity support so for that I am waiting.