In my opinion, the question shouldn't be "is the user on a phone or a tablet", because that's hiding the real question: "is the user on a device large enough that I should display a different UI?".
It is generally accepted that any device that is at least 600dp wide (on its shortest dimension) is a "tablet" for these purposes. And, as it turns out, the Android resource framework makes it really easy to use different drawables in these cases.
You probably already have your icons split up for different resolutions:
/res/drawable-mdpi/icon.png
/res/drawable-xhdpi/icon.png
etc
Use the same pattern, but add the sw600dp
qualifier for your "tablet" versions:
/res/drawable-sw600dp-mdpi/icon.png
/res/drawable-sw600dp-xhdpi/icon.png
etc
Now there's no need to write any Java code at all. If you have an <ImageView>
tag that specifies android:src="@drawable/icon"
, it will automatically use the "phone" version on smaller screens and the "tablet" version on any screen that's at least 600dp wide.