您不需要单独的 APK。
通过以下代码判断设备是手机还是平板
mFile = context.getFilesDir().getAbsoluteFile();
mDisplayMetrics = context.getResources().getDisplayMetrics();
connMan = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
final double x = Math.pow(mDisplayMetrics.widthPixels / mDisplayMetrics.xdpi, 2);
final double y = Math.pow(mDisplayMetrics.heightPixels / mDisplayMetrics.ydpi, 2);
mScreenInches = Math.sqrt(x + y);
如果mScreenUnches < 5它的电话
覆盖 onConfigurationChanged 并根据屏幕大小进行限制
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}