![]() |
|
|
概念 我们通过以下代码可以获取手机的能力,从而针对不同能力的手机做出显示彩色还是黑白色的图片,显示的字体是否可以为彩色等等。
还可以进一步通过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()); 还可以进一步通过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 { 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 ==============- - [MobileDeviceManufacturer ]: - [MobileDeviceModel ]: - [GatewayVersion ]: - [GatewayMajorVersion ]:<4> - [GatewayMinorVersion ]:<0> - [PreferredRenderingType ]: - [PreferredRenderingMime ]: - [PreferredImageMime ]: - [ScreenCharactersWidth ]:<20> - [ScreenCharactersHeight ]:<4> - [ScreenPixelsWidth ]:<90> - [ScreenPixelsHeight ]:<40> - [ScreenBitDepth ]:<1> - [IsColor ]: - [InputType ]: 上一页12 3 下一页
上一篇:J2ME中用MMAPI开发手机摄像头程序 下一篇:移动3D手机游戏开发的高级应用
|