操作系统  办公  实用知识  设计  开发  WEB开发  移动开发  数据库  软件工程  网管  安全  管理  信息化  答疑  渠道 

查看手机对JAVA的支持信息

2007-9-30 网友评论 0 条 点击进入论坛

  我们在开发J2ME的时候,都需要知道手机到底支持JAVA到哪种程度,比如CLDC1.0还是CLDC1.1对于简表的支持是MIDP1.0还是MIDP2.0或者是最新的MIDP2.1.

  如果有一个程序它在手机上一运行就知道这些配置的话,在某种程度上也方便了开发,其实要实现这个一点都不难,下面就是我写的用于检测手机的一些参数.程序里面只检测了一部份,大家可以根据需要加上自己需要知道的内容.

  首先是一个MIDlet,这是不能少的

  /*

  * Main.java

  *

  * Created on 2007-9-20, 15:08:53

  *

  * To change this template, choose Tools | Templates

  * and open the template in the editor.

  */

  package com.hadeslee.phone;

  import javax.microedition.midlet.*;

  import javax.microedition.lcdui.*;

  /**

  * @author hadeslee

  */

  public class Main extends MIDlet {

  private InfoForm info;

  public Main(){

  initOther();

  }

  public Display getDisplay(){

  return Display.getDisplay(this);

  }

  //初始化一些东西

  private void initOther(){

  info=new InfoForm(this);

  }

  public void startApp() {

  getDisplay().setCurrent(info);

  }

  public void pauseApp() {

  }

  public void destroyApp(boolean unconditional) {

  }

  }

  然后是包含了信息的一个Form

  /*

  * InfoForm.java

  *

  * Created on 2007-9-20, 15:10:02

  *

  * To change this template, choose Tools | Templates

  * and open the template in the editor.

  */

  package com.hadeslee.phone;

  import javax.microedition.lcdui.Alert;

  import javax.microedition.lcdui.AlertType;

  import javax.microedition.lcdui.Command;

  import javax.microedition.lcdui.CommandListener;

  import javax.microedition.lcdui.Displayable;

  import javax.microedition.lcdui.Form;

  import javax.microedition.lcdui.StringItem;

  import javax.microedition.lcdui.Ticker;

  /**

  *

  * @author hadeslee

  */

  public class InfoForm extends Form implements CommandListener {

  private Main main;

  private Command about;

  private Command exit;

  public InfoForm(Main main) {

  super("配置表");

  this.main=main;

  initOther();

  }

  //初始化其它

  private void initOther() {

  about = new Command("关于", Command.OK, 1);

  exit = new Command("退出", Command.EXIT, 1);

  this.addCommand(about);

  this.addCommand(exit);

  this.setCommandListener(this);

  this.setTicker(new Ticker("手机JAVA平台参数查看"));

  initStringItem();

  }

  //初始化字符串项

  private void initStringItem() {

  String[] keys = {"手机平台", "手机编码", "配置", "简表", "地区", "主机名"};

  String[] values = {"microedition.platform", "microedition.encoding", "microedition.configuration", "microedition.profiles", "microedition.locale", "microedition.hostname"};

  for (int i = 0; i < keys.length; i++) {

  StringItem item = new StringItem(keys[i], System.getProperty(values[i]));

  this.append(item);

  }

  }

  public void commandAction(Command c, Displayable d) {

  if (c == about) {

  main.getDisplay().setCurrent(new Alert("关于 ",

  "查看手机的一些JAVA配置 作者:千里冰封",null,AlertType.INFO), this);

  } else if (c == exit) {

  main.notifyDestroyed();

  main.destroyApp(true);

  }

  }

  }

  在这里我只列举出来了"microedition.platform", "microedition.encoding", "microedition.configuration", "microedition.profiles", "microedition.locale", "microedition.hostname"的信息,其实还有很多别的信息是可以知道的,下面是所有可查询的信息列表:

  JSR-Property Name Default-Value1

  30-microedition.platform-null

  microedition.encoding-ISO8859_1

  microedition.configuration-CLDC-1.0

  microedition.profiles-null

  37-microedition.locale-null

  microedition.profiles-MIDP-1.0

  75-microedition.io.file.FileConnection.version-1.0

  file.separator-(impl-dep)

  microedition.pim.version-1.0

  118 microedition.locale-null

  microedition.profiles-MIDP-2.0

  microedition.commports-(impl-dep)

  microedition.hostname-(impl-dep)

  120 wireless.messaging.sms.smsc-(impl-dep)

  139 microedition.platform-(impl-dep)

  microedition.encoding-ISO8859-1

  microedition.configuration-CLDC-1.1

  microedition.profiles-(impl-dep)

  177 microedition.smartcardslots-(impl-dep)

  179 microedition.location.version-1.0

  180 microedition.sip.version-1.0

  184 microedition.m3g.version-1.0

  185 microedition.jtwi.version-1.0

  195 microedition.locale-(impl-dep)

  microedition.profiles-IMP-1.0

  205 wireless.messaging.sms.smsc-(impl-dep)

  205 wireless.messaging.mms.mmsc-(impl-dep)

  不能保证以上都有效,因为手机支持度不一样,从JSR30到JSR205都有不同的参数可以让我们知道.

  另外我们也可以通过MIDlet的getAppProperty(String key)来得到我们定义在JAD文件里面的一些参数,这样就便于我们发布程序了.

已有 0 位对此文章感兴趣的网友发布了看法    
我来评两句 登录邮箱: 密码:
  匿名发表
今日推荐
技术文库(共有 46430 篇文章)
操作系统
办公软件
实用知识
网络管理
软件开发
WEB开发
软件工程
数据库
设计在线
信息安全
行业信息化
管理信息化
重点推荐
电子杂志订阅
点击电子杂志名称查看样刊
输入E-mail地址即可订阅
E-mail