[Wap] 识别访问手机的能力
[Wap] 识别访问手机的能力
Code |
日期 |
关键词 |
codeproject.com |
2005-7-28 |
Wap ASP.NET MobileCapabilities |
概念
我们通过以下代码可以获取手机的能力,从而针对不同能力的手机做出显示彩色还是黑白色的图片,显示的字体是否可以为彩色等等。
还可以进一步通过System.Web.Mobile.MobileCapabilities 的成员函数
System.Boolean HasCapability ( System.String delegateName , System.String optionalParameter )来查询手机是否支持某一特性,代码如下:
bool bHasWBMP =
((MobileCapabilities)Request.Browser).HasCapability("PreferredImageMime", "image/vnd.wap.wbmp");
log.Info("Has WBMP?" + bHasWBMP.ToString());
MobileCapabilities Codes
在asp.net页面中安排如下代码即可通过log4net打印出手机的MobileCapabilities:
代码: |
private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { log.Info("-============ 输出MobileCapabilities Begin ==============-"); Type myType =(typeof(System.Web.Mobile.MobileCapabilities)); System.Reflection.PropertyInfo[] myPropertyInfo = myType.GetProperties(System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Instance); DisplayPropertyInfo(myType, myPropertyInfo); log.Info("-============ 输出MobileCapabilities End ==============-"); } 。。。} void DisplayPropertyInfo(Type t,System.Reflection.PropertyInfo[] myPropertyInfo) { // Display information for all properties. System.Web.Mobile.MobileCapabilities m=( System.Web.Mobile.MobileCapabilities)Request.Browser; for(int i=0;i<myPropertyInfo.Length;i++) { Object result=new Object(); System.Reflection.PropertyInfo myPropInfo = (System.Reflection.PropertyInfo)myPropertyInfo[i]; try { result = t.InvokeMember (myPropInfo.Name, System.Reflection.BindingFlags.GetProperty|System.Reflection.BindingFlags.GetField, null, m, new object [] {}); } catch (System.MissingMethodException e) { result =e.Message; } log.Info ("[" + myPropInfo.Name+ " ]:<" + result+">"); } } |
下面日志对应的手机型号是
Nokia7610/2.0 (4.0424.4ch) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0 Configuration/CLDC-1.0
输出的日志如下: |
- -============ 输出MobileCapabilities Begin ==============- |
。
设备能力表格(FROM MSDN)
下面是asp.net mobile control所列出的设备属性表(来自于
):
Property |
WML |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
No | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
No | |
Yes | |
Yes | |
Yes | |
Yes | |
No | |
No | |
No | |
Yes | |
Yes | |
Yes | |
No | |
Yes | |
Yes | |
Yes | |
No | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
Yes | |
No | |
No | |
No | |
Yes | |
Yes | |
No | |
No | |
No | |
No | |
No | |
No | |
No | |
No | |
No | |
No | |
No | |
No | |
Yes | |
No | |
Yes |
编写者 |
日期 |
关键词 |
郑昀@ultrapower |
2005-7-28 |
Wap ASP.NET MobileCapabilities |