Android Question distinguish if device has a notch or not?

Discussion in 'Android Questions' started by Gunther, Feb 26, 2019.

  1. Gunther

    Gunther Active Member Licensed User

  2. Brandsum

    Brandsum Well-Known Member Licensed User

    Code:
    Dim ctxt As JavaObject
    ctxt.InitializeContext

    Dim JO As JavaObject = ctxt.RunMethodJO("getWindow"Null)
    JO = JO.RunMethodJO(
    "getDecorView"Null)
    JO = JO.RunMethodJO(
    "getRootWindowInsets",Null)
    JO = JO.RunMethodJO(
    "getDisplayCutout",Null)

    If JO.IsInitialized Then
        
    Log("Device has a notch")
        JO = JO.RunMethodJO(
    "getSafeInsetTop",Null)
        
    Log("Notch Height: " & JO)
    End If
    Check this documentation for more details: https://developer.android.com/reference/android/view/DisplayCutout
     
  3. capisx

    capisx Member Licensed User

    I've tried this code but the "JO" always return 'Not initialized', tested both in emulator and phone with notch.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Note that this method is only available on Android 8+. The code is correct. If it is not initialized then the device doesn't have a notch or doesn't support this feature properly.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice