Saturday 30 June 2012

Get DeviceType, Android API Level , OS Version and Application Version in Android

int osv=Build.VERSION.SDK_INT;
   String osv2=Build.VERSION.RELEASE;

 DisplayMetrics dm = new DisplayMetrics();
         getWindowManager().getDefaultDisplay().getMetrics(dm);
       
         if(dm.widthPixels<600)
             {
                DeviceType="Android SmartPhone";
             }
         else
             {
                 DeviceType="Android Tablet";
             }
       
       
         String model2=android.os.Build.BRAND;       
         System.out.println("BRAND is "+model2+" "+DeviceType);
         String brandname = model2.substring(0,1).toUpperCase() + model2.substring(1);
         DeviceType=brandname+" "+DeviceType;
         try
             {
                 app_ver =Integer.toString( this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode);
             }
         catch (NameNotFoundException e1)
            {
                 e1.printStackTrace();
            }
       
       androidinfo.setText(" DeviceType:  "+ DeviceType+"  \n "+"Android:  API Level "+osv+"  OS Version "+osv2+"\n Application Version:  "+app_ver);
        

No comments:

Post a Comment