相关疑难解决方法(0)

强制"纵向"方向模式

我正在尝试为我的应用程序强制"纵向"模式,因为我的应用程序绝对不是为"横向"模式设计的.

在阅读了一些论坛后,我在清单文件中添加了这些行:

<application 
  android:debuggable="true"
  android:icon="@drawable/icon" 
  android:label="@string/app_name"
  android:screenOrientation="portrait">
Run Code Online (Sandbox Code Playgroud)

但它不适用于我的设备(HTC Desire).它从"纵向"lo"横向"切换,忽略清单文件中的行.

在更多论坛阅读之后,我尝试在我的清单文件中添加它:

<application 
  android:debuggable="true"
  android:icon="@drawable/icon" 
  android:label="@string/app_name"
  android:configChanges="orientation"       
  android:screenOrientation="portrait">
Run Code Online (Sandbox Code Playgroud)

这个函数在我的activity类中:

public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Run Code Online (Sandbox Code Playgroud)

但同样,没有运气.

android landscape portrait screen orientation

285
推荐指数
5
解决办法
22万
查看次数

确定设备是智能手机还是平板电脑?

我想获得有关设备的信息,看看它是智能手机还是平板电脑.我该怎么做?

我想根据设备类型显示来自资源的不同网页:

String s="Debug-infos:";
s += "\n OS Version: " + System.getProperty("os.version") + "(" +    android.os.Build.VERSION.INCREMENTAL + ")";
s += "\n OS API Level: " + android.os.Build.VERSION.SDK;
s += "\n Device: " + android.os.Build.DEVICE;
s += "\n Model (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")";
Run Code Online (Sandbox Code Playgroud)

但是,对我来说似乎没用.


这个解决方案现在适用于我:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;

if (SharedCode.width > 1023 || SharedCode.height > 1023){
   //code for big screen (like tablet)
}else{ …
Run Code Online (Sandbox Code Playgroud)

android device-detection

251
推荐指数
7
解决办法
16万
查看次数