3

I am writing an app that the layout is a little off on the Droid X2. Is there a way to detect in code if the device is a Droid X2? I would like to add a small amount amount of padding to the layout if it is.

Thanks

Bobbake4
  • 24,509
  • 9
  • 59
  • 94
  • 1
    Shouldn't you rather figure out what exactly is causing things to be off and then detect that instead of detecting the specific device? – Matti Virkkunen Jul 13 '11 at 22:00

2 Answers2

3

Use Build.PRODUCT.

Sample code:

if (Build.PRODUCT.contains("droid x2")) {
    // Add stuff.
}

Another important point to add. If this doesn't work, make sure to debug what the Build.PRODUCT contains in order to see if that is the correct info. Otherwise, you can check what Build.MODEL returns and go with that.

Wroclai
  • 26,835
  • 7
  • 76
  • 67
  • 1
    I don't think that is a reliable way to tell. Some users uses custom ROMs that may have different values. – ming_codes Jul 13 '11 at 22:16
  • Correct. Users with custom ROM:s can customize stuff, so I will, in this case, just think of users with standard values. – Wroclai Jul 13 '11 at 22:19
2

Would this help? You could have a variable change based on the screen size instead of manually changing for devices:

getWindow().getWindowManager().getDefaultDisplay().getWidth();
getWindow().getWindowManager().getDefaultDisplay().getHeight();
RedLeader
  • 657
  • 1
  • 15
  • 28