[Wap] 识别访问手机的能力

简介:

[Wap] 识别访问手机的能力

Code

日期

关键词

codeproject.com

2005-7-28

Wap ASP.NET MobileCapabilities

 

概念

我们通过以下代码可以获取手机的能力,从而针对不同能力的手机做出显示彩色还是黑白色的图片,显示的字体是否可以为彩色等等。
 

还可以进一步通过System.Web.Mobile.MobileCapabilities 的成员函数

System.Boolean HasCapability ( System.String delegateName , System.StringoptionalParameter )来查询手机是否支持某一特性,代码如下:

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 ==============-
 - [MobileDeviceManufacturer ]:<Nokia>
 - [MobileDeviceModel ]:<Unknown>
 - [GatewayVersion ]:<Nokia WAP Gateway 4.0/CD3/4.0.04)>
 - [GatewayMajorVersion ]:<4>
 - [GatewayMinorVersion ]:<0>
 - [PreferredRenderingType ]:<wml11>
 - [PreferredRenderingMime ]:<text/vnd.wap.wml>
 - [PreferredImageMime ]:<image/vnd.wap.wbmp>
 - [ScreenCharactersWidth ]:<20>
 - [ScreenCharactersHeight ]:<4>
 - [ScreenPixelsWidth ]:<90>
 - [ScreenPixelsHeight ]:<40>
 - [ScreenBitDepth ]:<1>
 - [IsColor ]:<False>
 - [InputType ]:<telephoneKeypad>
 - [NumberOfSoftkeys ]:<2>
 - [MaximumSoftkeyLabelLength ]:<5>
 - [CanInitiateVoiceCall ]:<True>
 - [CanSendMail ]:<False>
 - [HasBackButton ]:<False>
 - [RendersWmlDoAcceptsInline ]:<False>
 - [RendersWmlSelectsAsMenuCards ]:<False>
 - [RendersBreaksAfterWmlAnchor ]:<True>
 - [RendersBreaksAfterWmlInput ]:<True>
 - [RendersBreakBeforeWmlSelectAndInput ]:<False>
 - [RequiresPhoneNumbersAsPlainText ]:<True>
 - [RequiresUrlEncodedPostfieldValues ]:<False>
 - [RequiredMetaTagNameValue ]:<>
 - [RendersBreaksAfterHtmlLists ]:<True>
 - [RequiresUniqueHtmlInputNames ]:<False>
 - [RequiresUniqueHtmlCheckboxNames ]:<False>
 - [SupportsCss ]:<False>
 - [HidesRightAlignedMultiselectScrollbars ]:<False>
 - [IsMobileDevice ]:<True>
 - [RequiresAttributeColonSubstitution ]:<False>
 - [CanRenderOneventAndPrevElementsTogether ]:<False>
 - [CanRenderInputAndSelectElementsTogether ]:<True>
 - [CanRenderAfterInputOrSelectElement ]:<True>
 - [CanRenderPostBackCards ]:<False>
 - [CanRenderMixedSelects ]:<True>
 - [CanCombineFormsInDeck ]:<True>
 - [CanRenderSetvarZeroWithMultiSelectionList ]:<True>
 - [SupportsImageSubmit ]:<False>
 - [RequiresUniqueFilePathSuffix ]:<True>
 - [RequiresNoBreakInFormatting ]:<False>
 - [RequiresLeadingPageBreak ]:<False>
 - [SupportsSelectMultiple ]:<True>
 - [SupportsBold ]:<False>
 - [SupportsItalic ]:<False>
 - [SupportsFontSize ]:<False>
 - [SupportsFontName ]:<False>
 - [SupportsFontColor ]:<True>
 - [SupportsBodyColor ]:<True>
 - [SupportsDivAlign ]:<True>
 - [SupportsDivNoWrap ]:<False>
 - [RequiresContentTypeMetaTag ]:<False>
 - [RequiresDBCSCharacter ]:<False>
 - [RequiresHtmlAdaptiveErrorReporting ]:<False>
 - [RequiresOutputOptimization ]:<False>
 - [SupportsAccesskeyAttribute ]:<False>
 - [SupportsInputIStyle ]:<False>
 - [SupportsInputMode ]:<False>
 - [SupportsIModeSymbols ]:<False>
 - [SupportsJPhoneSymbols ]:<False>
 - [SupportsJPhoneMultiMediaAttributes ]:<False>
 - [MaximumRenderedPageSize ]:<1397>
 - [RequiresSpecialViewStateEncoding ]:<False>
 - [SupportsQueryStringInFormAction ]:<True>
 - [SupportsCacheControlMetaTag ]:<True>
 - [SupportsUncheck ]:<True>
 - [CanRenderEmptySelects ]:<True>
 - [SupportsRedirectWithCookie ]:<True>
 - [SupportsEmptyStringInCookieValue ]:<True>
 - [DefaultSubmitButtonLimit ]:<1>
 - [ClrVersion ]:<0.0>
 - [Type ]:<Unknown>
 - [Browser ]:<Nokia>
 - [Version ]:<0.0>
 - [MajorVersion ]:<0>
 - [MinorVersion ]:<0>
 - [Platform ]:<Unknown>
 - [TagWriter ]:<System.Web.UI.Html32TextWriter>
 - [EcmaScriptVersion ]:<0.0>
 - [MSDomVersion ]:<0.0>
 - [W3CDomVersion ]:<0.0>
 - [Beta ]:<False>
 - [Crawler ]:<False>
 - [AOL ]:<False>
 - [Win16 ]:<False>
 - [Win32 ]:<False>
 - [Frames ]:<False>
 - [Tables ]:<False>
 - [Cookies ]:<False>
 - [VBScript ]:<False>
 - [JavaScript ]:<False>
 - [JavaApplets ]:<False>
 - [ActiveXControls ]:<False>
 - [BackgroundSounds ]:<False>
 - [CDF ]:<False>
 
- -============ 
输出MobileCapabilities End ==============-


 

设备能力表格(FROM MSDN)

下面是asp.net mobile control所列出的设备属性表(来自于

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mwsdk/html/mwlrfDeviceSpecificElement.asp

):

Property

WML

Browser

Yes

CanCombineFormsInDeck

Yes

CanInitiateVoiceCall

Yes

CanRenderEmptySelects

Yes

CanRenderInputAndSelectElementsTogether

Yes

CanRenderMixedSelects

Yes

CanRenderOneventAndPrevElementsTogether

Yes

CanRenderPostbackCards

Yes

CanRenderSetvarZeroWithMultiSelectionList

Yes

CanSendMail

Yes

DefaultSubmitButtonLimit

Yes

GatewayMajorVersion

Yes

GatewayMinorVersion

Yes

GatewayVersion

Yes

HasBackButton

Yes

HidesRightAlignedMultiselectScrollbars

No

InputType

Yes

IsColor

Yes

IsMobileDevice

Yes

Item

Yes

MaximumRenderedPageSize

Yes

MaximumSoftKeyLabelLength

Yes

MobileDeviceManufacturer

Yes

MobileDeviceModel

Yes

NumberOfSoftkeys

Yes

PreferredImageMime

Yes

PreferredRenderingMime

Yes

PreferredRenderingType

Yes

RendersBreakBeforeWmlSelectAndInput

Yes

RendersBreaksAfterHtmlLists

No

RendersBreaksAfterWmlAnchor

Yes

RendersBreaksAfterWmlInput

Yes

RendersWmlDoAcceptsInline

Yes

RendersWmlSelectsAsMenuCards

Yes

RequiredMetaTagNameValue

No

RequiresContentTypeMetaTag

No

RequiresAttributeColonSubstitution

No

RequiresHtmlAdaptiveErrorReporting

Yes

RequiresLeadingPageBreak

Yes

RequiresNoBreakInFormatting

Yes

RequiresOutputOptimization

No

RequiresPhoneNumbersAsPlainText

Yes

RequiresSpecialViewStateEncoding

Yes

RequiresUniqueFilePathSuffix

Yes

RequiresUniqueHtmlCheckboxNames

No

RequiresUniqueHtmlInputNames

Yes

RequiresUrlEncodedPostfieldValues

Yes

ScreenBitDepth

Yes

ScreenCharactersHeight

Yes

ScreenCharactersWidth

Yes

ScreenPixelsHeight

Yes

ScreenPixelsWidth

Yes

SupportsAccesskeyAttribute

No

SupportsBodyColor

No

SupportsBold

No

SupportsCacheControlMetaTag

Yes

SupportsCss

Yes

SupportsDivAlign

No

SupportsDivNoWrap

No

SupportsFontColor

No

SupportsFontName

No

SupportsFontSize

No

SupportsImageSubmit

No

SupportsIModeSymbols

No

SupportsInputIStyle

No

SupportsInputMode

No

SupportsItalic

No

SupportsJPhoneMultiMediaAttributes

No

SupportsJPhoneSymbols

No

SupportsQueryStringInFormAction

Yes

SupportsSelectMultiple

No

SupportsUncheck

Yes

 

目录
相关文章
|
3月前
|
存储 移动开发 Android开发
使用kotlin Jetpack Compose框架开发安卓app, webview中h5如何访问手机存储上传文件
在Kotlin和Jetpack Compose中,集成WebView以支持HTML5页面访问手机存储及上传音频文件涉及关键步骤:1) 添加`READ_EXTERNAL_STORAGE`和`WRITE_EXTERNAL_STORAGE`权限,考虑Android 11的分区存储;2) 配置WebView允许JavaScript和文件访问,启用`javaScriptEnabled`、`allowFileAccess`等设置;3) HTML5页面使用`<input type="file">`让用户选择文件,利用File API;
|
4月前
Discuz 手机版访问自动跳转到手机域名
Discuz 手机版访问自动跳转到手机域名
85 1
|
3月前
|
JavaScript
vue 项目/备案网页/ip网页打包成 apk 安装到平板/手机(含vue项目跨域代理打包成apk后无法访问接口的解决方案)
vue 项目/备案网页/ip网页打包成 apk 安装到平板/手机(含vue项目跨域代理打包成apk后无法访问接口的解决方案)
94 0
|
3月前
|
Web App开发
软件开发常见流程之移动端调试方法,利用Chrome(谷歌浏览器)的模拟手机调试,搭建本地Web服务器,手机和服务器在一个局域网,通过手机访问服务器,使用服务器,利用ip实现域名访问
软件开发常见流程之移动端调试方法,利用Chrome(谷歌浏览器)的模拟手机调试,搭建本地Web服务器,手机和服务器在一个局域网,通过手机访问服务器,使用服务器,利用ip实现域名访问
|
4月前
|
JavaScript
技术心得:根据不同访问设备跳转到PC页面或手机页面
技术心得:根据不同访问设备跳转到PC页面或手机页面
48 0
|
5月前
|
iOS开发
如何识别手机是否有灵动岛(dynamic island)
如何识别手机是否有灵动岛(dynamic island)
237 0
|
5月前
|
JavaScript
利用Termux和cpolar在手机上搭建Hexo博客,实现远程访问的完整指南
利用Termux和cpolar在手机上搭建Hexo博客,实现远程访问的完整指南
56 0
|
5月前
|
网络协议 安全 Linux
如何使用Android手机通过JuiceSSH远程访问本地Linux服务器
如何使用Android手机通过JuiceSSH远程访问本地Linux服务器
|
5月前
|
传感器 人工智能 监控
Java智慧工地管理云平台源码 带AI识别、桌面管理+大屏指挥+手机APP
智慧工地平台支持项目级、公司级、集团级多级权限划分,可根据企业的组织架构进行项目权限、功能权限、数据权限设定。
149 0
|
5月前
|
移动开发
解决网页、H5页面在手机端访问时,底部会有一段莫名其妙的空白,大约有几百像素高的留白
解决网页、H5页面在手机端访问时,底部会有一段莫名其妙的空白,大约有几百像素高的留白