このコードを呼び出すと、画面密度を確認できます。
int screen_density = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
if (screen_density == Configuration.SCREENLAYOUT_SIZE_LARGE || screen_density == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
//The device is a tablet or at least has the screen density of a tablet
}
以下のコードで画面サイズを取得することもできます。
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
最後に、android Honeycomb(3.+) はタブレットでのみ実行されるため、次を使用して Android のバージョンを確認できます。
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if(currentapiVersion == android.os.Build.VERSION_CODES.HONEYCOMB ||
currentapiVersion == android.os.Build.VERSION_CODES.HONEYCOMB_MR1 ||
currentapiVersion == android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
//The device is a tablet
}
編集: 明確にするために、上記のコードは、デバイスをタブレットとして分類するためのデバイスの画面サイズと密度に関心があることを前提としています。Michael Kohne の回答から述べたように、この分類を困難にする多くの技術的側面があります (不可能ではないにしても)。
お役に立てれば:)