2
\$\begingroup\$

There are new "foldable" mobile devices such as Samsung foldable phones.

Is there any way we can write a C# script in Unity to detect if the device is a foldable phone ?

I try, but can't find any online tutorial on how to do this yet.

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Searching for "samsung foldable phone api" brings up the Android developer documentation on foldables which links to the information on making your app fold aware:

To make your app fold aware, use the Jetpack WindowManager library, which provides an API surface for foldable device window features

All of the code examples in the above mentioned Android developer documentation are in Java or Kotlin. However, searching for "Jetpack WindowManager library c#" brings up Microsoft's documentation for the Jetpack Window Manager for Unity. The Microsoft docs include Unity game samples for Surface Duo and an accompanying explainer blog post:

To access the new APIs from Unity, copy the C# code from the file SurfaceDuoScreenHelper.cs from GitHub into your game. This will provide the following functionality:

DeviceHelper.IsDualScreenDevice – Call this method before accessing other dual-screen APIs.

IsDualScreenDevice() returns a bool indicating whether your app is running on a dual-screen device.

\$\endgroup\$
5
  • \$\begingroup\$ That's a great answer. -- BTW, If I want to build a Unity APK for only foldable phones, would you please tell me how to do that ? I have posted a new question for that one here: gamedev.stackexchange.com/questions/203757/… \$\endgroup\$ Commented Dec 18, 2022 at 21:29
  • \$\begingroup\$ @Job_September_2020 If the answer was useful & you've not yet done so, consider up voting. If it solves you problem, consider marking it as the accepted answer. \$\endgroup\$ Commented Dec 20, 2022 at 15:58
  • \$\begingroup\$ does this also work f or pixel fold or just microsoft? \$\endgroup\$ Commented Jul 16, 2024 at 9:44
  • \$\begingroup\$ how do you tell which part of the screen is the top or bottom fold? \$\endgroup\$ Commented Jul 16, 2024 at 9:50
  • \$\begingroup\$ @ina My understanding is that C# Jetpack Window Manager library wraps the native Java API and it's used in this Samsung foldables tutorial, so it should work with foldables in general. You can use the API to find the fold bounds - the specifics don't fit/format well in a comment & probably merit their own question anyway. \$\endgroup\$ Commented Jul 16, 2024 at 16:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.