Androd Programming,is the device a Tablet or a Phone ?

by 2:31 AM 0 comments
My app design would look bad on tablets so i wrote this code to get the devices type (tablet or phone) :

public boolean isTablet(Context context)
{
        return
 (context.getResources().getConfiguration().screenLayout 
             & Configuration.SCREENLAYOUT_SIZE_MASK ) >= 
                Configuration.SCREENLAYOUT_SIZE_LARGE;
}


then i changed the design layout based on the device type that was returned from the method isTablet(); with this code:


boolean  tablet = isTablet(this)
       
     if (tablet)
               setContentView(R.layout.tablet_design);
            else 
               setContentView(R.layout.phone_design);




Unknown

Android Developer at Appsix LLC

I love stickers and reading books. A cool website that I've found was commitstrip.com
Currently reading: The pragmatic programmer, and The C programming language.
Currently working: an android app, and on a web project with laravel.
Im a 9gag enthusiast.
I write code at work and at home for fun or out of pure boredom.
Programming Languages that I've worked with: Java PHP C# PLSQL JavaScript
Thanks for reading.



0 comments :

Post a Comment