[经验分享] 获取设备支持的可选API
J2ME规范包括了许多可选包,如支持多媒体功能的MMAPI,支持消息接收和发送的WMA,支持3D游戏的M3G API。如果某一款手机支持某个可选API,MIDP应用程序就可以使用它。但是,让用户回答“本机是否支持MMAPI”是不友好的,发布几个不同版本不 但增加了开发的工作量,也让用户难以选择。因此,应用程序应该自己检测手机是否支持某一API,从而在运行期决定是否可以使用此API。 MIDP 1.0和2.0应用程序都可以通过System.getProperty(String key)检测某一个属性的信息。如果该属性有效,将返回对应的字符串,否则,返回null,表示系统不支持此功能。 例如,System.getProperty("microedition.profiles")可能的返回值是"MIDP-1.0"或"MIDP-2.0"。 以下是常见的系统属性和可选API的属性,右侧列出了可能的返回值:
boolean supports_take_photo = false; boolean supports_jpeg_encoding = false; boolean supports_png_encoding = false; boolean supports_gif_encoding = false; if(System.getProperty("microedition.media.version")!=null) { if("true".equals(System.getProperty("supports.video.capture"))) supports_take_photo = true; String all_encoding = System.getProperty("video.snapshot.encodings"); if(all_encoding!=null) { if(all_encoding.indexOf("jpeg")!=(-1)) supports_jpeg_encoding = true; if(all_encoding.indexOf("png")!=(-1)) supports_png_encoding = true; if(all_encoding.indexOf("gif")!=(-1)) supports_gif_encoding = true; } } } 在JSR规范里面 J2ME 是可以通过 System.getProperty(String key) 得到一些你想要的东东。 J2ME Defined System Properties [/tr]
¹(impl-dep) indicates that the default value is implementation-dependent. 我用Nokia 6303C 移动动感地带的环境下 测试过 wireless.messaging.sms.smsc 得到的是 13800100500 这个是北京的sim卡短信息中心号码 wireless.messaging.mms.mmsc 得到的是 http://mmsc.monternet.com 这个是彩信的东东 microedition.locale 得到的是zh-CN 其他的各位童鞋们 自己测试下吧 |