Is it possible to programmatically determine the device on which the software is running: a tablet or a smartphone? Determining by screen resolution is not an option, on many smartphones it is no worse than on tablets.

    1 answer 1

    Once I studied this question. In general, I came to the conclusion that everything that is less than 7 inches can be considered a smartphone, and what is more - a tablet. At the next iteration I did it differently - everything that is small (5 inches and less) was turned on in smart mode, more than 7 - in tablet mode. For all, more than 5 in the settings made it possible to choose an interface.

    After a lot of googling in the open spaces and consultations with android lawyers (these are specialists on solving questions on android), such code was received

    private bool isTabletModeDetermined = false; private bool isTabletMode = false; //.... public static boolean isTablet(Context paramContext) { if (!isTabletModeDetermined) { if (paramContext.getResources().getConfiguration().smallestScreenWidthDp>= 600) isTabletMode = true; isTabletModeDetermined = true; } return isTabletMode; } 

    They say that gTalk uses something like that.

    • Apparently, it is assumed that - the screen resolution in the android on the go does not change; - that the system call is very costly, since it needs to be cached. - gecube
    • Caching on android (and not only) helps a lot in terms of productivity. But the permission on the go if it changes, then I suspect that with high probability, the application will be restarted. (there is an experience with sdcard - when it is pulled out, and the application uses it, then the android simply restarts the application. And no problems :)) @gecube, do you know any devices where you can change permissions on the fly? - KoVadim
    • @KoVadim, not sure. But there seems to be utilities to change the density on the fly. - gecube
    • In any custom firmware. cyagen, for example. But I think it will restart the application. - KoVadim