안드로이드

[안드로이드/Android] 폰인지, 태블릿인지 구분하기

알통몬_ 2023. 4. 5. 11:58
반응형

1. TelephonyManager

val telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
if (telephonyManager.phoneType == TelephonyManager.PHONE_TYPE_NONE) {
    Toast.makeText(this, "Tablet", Toast.LENGTH_SHORT).show()
} else {
    Toast.makeText(this, "Mobile", Toast.LENGTH_SHORT).show()
}

2. Configuration

완벽하게 구분되지는 않는다. sw600dp 이상이면 태블릿으로, 이하이면 폰으로 구분된다.

val screenType = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
if(screenType == Configuration.SCREENLAYOUT_SIZE_SMALL || screenType == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
    Toast.makeText(this, "Mobile", Toast.LENGTH_SHORT).show()
} else if(screenType == Configuration.SCREENLAYOUT_SIZE_LARGE || screenType == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
    Toast.makeText(this, "Tablet", Toast.LENGTH_SHORT).show()
}

 

반응형