如何在html中获得android手机中浏览器的屏幕的宽度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在html中获得android手机中浏览器的屏幕的宽度相关的知识,希望对你有一定的参考价值。

在html中获得android手机中浏览器的屏幕宽度的方法:
1、在网页的<head>中增加以上这句话,可以让网页的宽度自动适应手机屏幕的宽度:

[html] view plaincopy
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
第一行:
width=device-width :表示宽度是设备屏幕的宽度
initial-scale=1.0:表示初始的缩放比例
minimum-scale=0.5:表示最小的缩放比例
maximum-scale=2.0:表示最大的缩放比例
user-scalable=yes:表示用户是否可以调整缩放比例
第二行:
设定iphone端页面全屏。
第三行:
取消数字被识别为电话号码。
2、如果是想要一打开网页,则自动以原始比例显示,并且不允许用户修改的话,则是:

[html] view plaincopy
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
3、这样可以把一些页头横幅等的图片的宽度都设置成style="width:100%",整个页面在设备上看起来就是全屏的了。
参考技术A android中放入html 无非是嵌再webView里。为什么要在html中获取呢,在webView所在的activity中获取不行么。
DisplayMetrics dm= new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

width= dm.widthPixels;

height= dm.heightPixels;
希望能对你有所帮助本回答被提问者和网友采纳
参考技术B android中放入html 无非是嵌再webView里。为什么要在html中获取呢,在webView所在的activity中获取不行么。
DisplayMetrics dm= new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

width= dm.widthPixels;

height= dm.heightPixels;
希望能对你有所帮助
参考技术C android中放入html 无非是嵌再webView里。为什么要在html中获取呢,在webView所在的activity中获取不行么。
DisplayMetrics dm= new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

width= dm.widthPixels;

height= dm.heightPixels;

Android 怎样获得手机信息

在Android中,想要获取系统信息,可以调用其提供的方法System.getProperty(propertyStr),而系统信息诸如用户根目录(user.home)等都可以通过这个方法获取,实现代码如下:

Java代码:
public static StringBuffer buffer = null;
private static String initProperty(String description,String propertyStr)
if (buffer == null)
buffer = new StringBuffer();

buffer.append(description).append(":");
buffer.append (System.getProperty(propertyStr)).append(" ");
return buffer.toString();

private static String getSystemProperty()
buffer = new StringBuffer();
initProperty("java.vendor.url","java.vendor.url");
initProperty("java.class.path","java.class.path");
return buffer.toString();


上述代码主要是通过调用系统提供的System.getProperty方法获取指定的系统信息,并合并成字符串返回。

  1.2.2.3 运营商信息

  运营商信息中包含IMEI、手机号码等,在Android中提供了运营商管理类(TelephonyManager),可以通过TelephonyManager来获取运营商相关的信息,实现的关键代码如下:

Java代码:
public static String fetch_tel_status(Context cx)
String result = null;
TelephonyManager tm = (TelephonyManager) cx.getSystemService(Context.TELEPHONY_SERVICE);
String str = " ";
str += "DeviceId(IMEI) = " + tm.getDeviceId() + " ";
str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion()+" ";
// TODO: Do something ...
int mcc = cx.getResources().getConfiguration().mcc;
int mnc = cx.getResources().getConfiguration().mnc;
str +="IMSI MCC (Mobile Country Code): " +String.valueOf(mcc) + " ";
str +="IMSI MNC (Mobile Network Code): " +String.valueOf(mnc) + " ";
result = str;
return result;
在上述的代码中,首先调用系统的getSystemService (Context.TELEPHONY_SERVICE)方法获取一个TelephonyManager对象tm,进而调用其方法 getDeviceId()获取DeviceId信息,调用getDeviceSoftware Version()获取设备的软件版本信息等。

  1.2.3 查看硬件信息
  1.2.3.1 获取CPU信息

  可以在手机设备的/proc/cpuinfo中获取CPU信息,调用CMDEexecute执行系统的cat的命令,取/proc/cpuinfo的内容,显示的就是其CPU信息,实现代码如下:

Java代码:

在上述的代码中,首先调用系统的getSystemService (Context.TELEPHONY_SERVICE)方法获取一个TelephonyManager对象tm,进而调用其方法 getDeviceId()获取DeviceId信息,调用getDeviceSoftware Version()获取设备的软件版本信息等。

  1.2.3 查看硬件信息
  1.2.3.1 获取CPU信息

  可以在手机设备的/proc/cpuinfo中获取CPU信息,调用CMDEexecute执行系统的cat的命令,取/proc/cpuinfo的内容,显示的就是其CPU信息,实现代码如下:

Java代码:
public static String fetch_cpu_info()
String result = null;
CMDExecute cmdexe = new CMDExecute();
try
String[ ] args = "/system/bin/cat", "/proc/cpuinfo";
result = cmdexe.run(args, "/system/bin/");
Log.i("result", "result=" + result);
catch (IOException ex)
ex.printStackTrace();

return result;

上述代码使用CMDExecute,调用系统中的"/system/bin/cat"命令查看"/proc/cpuinfo"中的内容,即可得到CPU信息。
参考技术A 系统信息

在Android中,想要获取系统信息,可以调用其提供的方法System.getProperty(propertyStr),而系统信息诸如用户根目录(user.home)等都可以通过这个方法获取。本回答被提问者采纳

以上是关于如何在html中获得android手机中浏览器的屏幕的宽度的主要内容,如果未能解决你的问题,请参考以下文章

你如何在Android中获得手机的MCC和MNC?

如何获得Android手机的软件安装列表

如何使用 android 手机上的本地 Google Maps .html 文件平移到当前位置?

如何使用javascript检测浏览器中的手机事件?

铁打的手机,流水的屏

Android14.3 浏览手机中的所有文件夹和文件