Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question C# How to find out if device is foldable?

Discussion in 'Android' started by Bordeaux_Fox, Nov 17, 2020.

  1. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Hi,

    I need a reliable method of checking if an Android device is a foldable phone like Samsung Fold.
    I thought "deviceType" would give me that info, but it's not. I need something like "supportsFolding". That would be handy. :)

    Other idea would be hard coding device models. But I like to avoid this.
     
  2. VaidasM

    VaidasM

    Unity Technologies

    Joined:
    Jun 27, 2017
    Posts:
    41
    Hey Bordeaux_Fox,

    unfortunately, there are currently no methods designed to achieve such a goal. One think you could try doing is distinguishing the device by the model by using SystemInfo.deviceModel :
    https://docs.unity3d.com/ScriptReference/SystemInfo-deviceModel.html

    Since there's a relatively small amount of foldable devices in the market, this solution could be used until proper API is implemented in Unity. For now, there are no such plans on the roadmap, but it's likely that such methods will be added once there are more foldable devices being released.
     
  3. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Hi, thanks for the answer. Yes I also had the fear this would be just too new for the moment. But nevertheless, I hope Unity will implement access the new API for foldables in Android in the near future: https://developer.android.com/guide/topics/ui/foldables

    Because my general intention for getting the device support is to use the additional feature set. Therefore I have some other questions:

    How can I access new features like hinge angle sensor or postures within Unity?
    Could I write my own code to have access to newest Android API or does it require a solution from Unity? I guess this would be implemented in the Unity.Android class?

    Another thing, it seems that switching from the main display to the cover display is supported by default. But I don't know if it is a standard resize behaviour from Unity or a new specific handling for foldables. If I go to my Android settings, it just says my Unity app is supporting switching the screens and I can turn the automatic switching on or off, depending on when I fold the screen. Not sure which callback is involved here.

    :)
     
    Last edited: Nov 30, 2020
  4. TeohRIK

    TeohRIK

    Joined:
    Jan 22, 2014
    Posts:
    106
    haha, this the only post I can find in Google for hoping they will integrate this feature in Unity. But ya definitely can write your own Android Library and use in Unity