Home > Net >  How to know if tablet or phone in Android
How to know if tablet or phone in Android

Time:07-08

I have a var in Swift like this :

@Published  var textFieldSize = UIDevice.current.userInterfaceIdiom == .pad ? 20.0 :  12.0

How can i get the same device type (phone or tablet) but in Jetpack Compose Android ??

CodePudding user response:

You can do this:

val configuration = LocalConfiguration.current
val expanded = configuration.screenWidthDp > 840

This corresponds to 97.22% of tablets in landscape. For sizes corresponding to phones or tablets there is more info here.

  • Related