Tablet or Phone - Android

后端 未结 30 2489
难免孤独
难免孤独 2020-11-22 08:33

Is there a way to check if the user is using a tablet or a phone? I\'ve got problems with my tilt function and my new tablet (Transformer)

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 09:18

    public boolean isTablet() {
            int screenLayout = getResources().getConfiguration().screenLayout;
            return (Build.VERSION.SDK_INT >= 11 &&
                    (((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) || 
                     ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE)));
        }
    

提交回复
热议问题