Android Question Do you have a fold-able device? could you test this routine

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have a user that has a 4 Fold and is having problems.

I want to be able to detect if the device is fold-able and wrote this code

B4X:
#Region IsDeviceFoldable
Private Sub IsDeviceFoldable As Boolean
            Dim Sensor_Hinge                    As String = "android.hardware.sensor.hinge_angle"
            
            Try 
                Dim jo As JavaObject
            
                jo.InitializeContext

                Dim IsFoldable As Boolean = False                
                
                IsFoldable = jo.RunMethodJO("getPackageManager", Null).RunMethod("hasSystemFeature", Array(Sensor_Hinge))
                
                LogColor($"IsDeviceFoldable ${IsFoldable}"$, Colors.Red)
                                
                Return IsFoldable
            Catch
                LogColor($"IsDeviceFoldable Failed - ${LastException.Message}"$, Colors.Red)
                
                Return False
            End Try
End Sub    
#end Region

I don't have a fold-able device so on all my devices this returns false.

Was wondering if someone had a device that folded and could let me know if this routine returns true.

Thanks

BobVal
 

Sagenut

Expert
Licensed User
Longtime User
Not the best test available but...
I have tried it on a Foldable Emulator and I get
IsDeviceFoldable true
 
Upvote 0

73Challenger

Active Member
Licensed User
I've got a ZFold3, I'll test it this evening. If you don't mind me asking, how are you using it? I'd like to reload...or at least re-draw my app on the foldable event but I haven't investigated doing it. I'd appreciate examples. I'll get back to you this evening about the code above. Thank you
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Good to hear that code seems to work.

73Challenger you ask what i was using it for:
I was having troubles with httputils see this thread https://www.b4x.com/android/forum/t...bmitjob-with-test-program.149624/page-2#posts
and added this code to my program
B4X:
Private Sub StartHttpUtils2Service
    #if release
    If HttpUtils2Service.TempFolder = "" Then
        Dim jo As JavaObject
        jo.InitializeNewInstance(Application.PackageName & ".httputils2service", Null)
        jo.RunMethod("onReceive", Array(Null, Null))
    End If
    #end if
End Sub

Adding the above code somehow (guessing) has caused a problem with a user (only one I know of with fold) with Firebase auth gets a lot of ApiException 10

was going to wrap the above code with the check for folding device and not do it and see if that fixes his problem.

Will try it and see what happens and report back

BobVal
 
Upvote 0
Top