文章标签 ‘WM’
2010十一月15

WM6.1 手机采购订单及GPS定位系统开发完成

某集团移动数据采集系统(采购、质检)开发告一段落,主要功能有客户拜访、收发货、质检单等数据上报,和ERP系统的接口,工作汇报等功能,有后台自动运行的每小时上传一次的GPS定位功能。

采购员可能到达全国各地,许多地方没有电脑上网条件,用移动终端智能手机系统能很好的解决此问题。

目前软件已在使用,不过在使用过程中也发现一些问题,如由于移动网络信号的问题,会出现网络传输中断不能上传的情况,此时就需要有本地保存批量上传功能;GPS定位的问题很怪,几个采购员出去,到目前为止仅有一个人能定位到,同样的程序其他人却不能定位,很奇怪……

2010九月29

C# Windows Mobile 实现休眠状态下定时任务

OpenNETCF.WindowsCE.LargeIntervalTimer llTimer = new OpenNETCF.WindowsCE.LargeIntervalTimer(); 

//第一次触发时间

llTimer.FirstEventTime = DateTime.Now;

llTimer.Interval = new TimeSpan(0, 30, 0);

//是否只触发一次

 llTimer.OneShot = false;

llTimer.Tick += new EventHandler(llTimer_Tick);

llTimer.Enabled = true;

static void llTimer_Tick(object sender, EventArgs e)

 {

             //

  }

 

来源:http://www.cnblogs.com/fox23/archive/2008/02/03/AtTime.html

opennetcf下载:http://www.opennetcf.com/Products/SmartDeviceFramework/tabid/65/Default.aspx

2010九月28

C# Windows Mobile 6 通过注册表实现开机自运行

方法1:制作CAB安装包

VS2005,新建项目–其他项目类型–安装和部署–智能Cab安装项目–在Program files里增加文件夹myexe

添加要可执行 a.exe。

打开注册表视图,在HKEY_LOCAL_MACHINE 增加 Init 文件夹,新建字符串 Launch98,值为

“\Program files\myexe\a.exe”

这样,安装cab之后重启下即可自运行。

private void Form1_Activated(object sender, EventArgs e)
        {
            this.Hide();  //隐藏窗体
        }

方法2:通过程序运行注册键值

 

  //注册开机
  //Registry.LocalMachine 对应于 HKEY_LOCAL_MACHINE主键
  RegistryKey key = Registry.LocalMachine.OpenSubKey("init", true);
  if (key.GetValue("Launch77") == null)
  {
       key.SetValue("Launch77", Assembly.GetExecutingAssembly().GetName().CodeBase);
       MessageBox.Show("注册成功!", "提示");
   }
   key.Close();
2010九月23

C# 解决中文乱码,把中文转换成UTF-8,UrlEncode

public statc string UrlEncode(string input)
        {
            if(input==null||"".Equals(input))return "";
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.Default.GetBytes(input);
            for(int i = 0; i < byStr.Length; i++)
            {
              sb.Append(@"%" + Convert.ToString(byStr[i],16));
            }

            return (sb.ToString());

        }
2010九月22

WM windows mobile 6.1 C#网络开发,程序自动升级等

终于的终于,还是用C#开发了,仿照了一些M8上软件界面。。

分享一些经验,由于时间太紧,有些功能是比较土的方法暂时实现的,之后还需升级。

1、网络传输

 public static string Login(string userName, string password)
        {
            string LOGIN_RES = "";
            try
            {

                string url = com.LOGIN_URL ;//url
                url = url + "&username=" + userName;
                url = url + "&password=" + password;

                HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
                objRequest.Method = "GET";
                objRequest.Timeout = 60 * 1000;
                //WebProxy proxy = new WebProxy("192.168.0.2:80", true);
                // proxy.Address = new Uri("");//按配置文件创建Proxy 地置
                //proxy.Credentials = new NetworkCredential("用户名", "密码");//从配置封装参数中创建
                //objRequest.Proxy = proxy; 

                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

                Stream objStream = objResponse.GetResponseStream();
                StreamReader objReader = new StreamReader(objStream, Encoding.GetEncoding(com.PageEnCode));
                LOGIN_RES=objReader.ReadToEnd();
                if (LOGIN_RES != null) LOGIN_RES = LOGIN_RES.Trim();
                objReader.Close();
                objStream.Close();

                return LOGIN_RES;

            }
            catch (Exception ex){
                Console.Write(ex.Message);
                return null;

            }

        }

2、程序升级

利用1里面的方法,读取服务器某网页文件,获取版本号和当前程序版本进行比较,若有最新版,

则在WM里打开浏览器进行下载:

private void checkUpdate()
        {
            int k = comHTTP.AutoUpdate();
            if (k > com.COPYRIGHT)
            {
                MessageBox.Show("\r\n系统监测到新版本,程序将自动打开下载,请安装后继续使用.\r\n\r\n", "提示");
                System.Diagnostics.Process.Start("IEXPLORE.EXE", "/autoupdate.cab");//打开IE,
                Application.Exit();

            }
        }
2010九月21

windows mobile模拟器如何联网?

windows mobile开发的时候模拟器如何联网?

1. 安装Active sync,到微软网站上面去找找,有免费下载。

2. 打开Active sync连接选项,里面有下拉选框的那个(允许连接到以下其中一个端口),选择DMA

3. 在VS2005里面启动模拟器成功(要知道自己连的是哪个)之后,Tools菜单里面有个”Device Emulator Manager”,找到刚刚连上的模拟器(前面会有个小图标,其他没启动就没有),右键点击,选择”Cradle” 这时候Active sync跳出来说找到一个device,不理他,等待emulator里面跳出个小对话框,告诉你连接成功(很快就自己消失),OK,这时候就可以上网了。

注意:Active Sync会吃掉所有的UDP包,所以用这种方式开发UDP客户端行不通了。

2010九月17

Java ME/J2ME 环境搭建、WM6.1运行JBED虚拟机手机实现JSR179定位

接触Java ME,到现在已经过去五天了。利用一款带GPS模块的WM6.1系统的手机实现定位和数据上报项目,周期为18天,公司没有一个人搞过手机开发,囧,身为研发部负责人责无旁贷(目前是光杆司令)……

废话不多讲,刚开始用MyEclispe + MyEclispeMe + WTK + JDK 搭建了开发环境(这也是费了九牛二虎之力)

一、Java ME/J2ME环境的搭建

1、安装 MyEclipse

MyEclipse_6.5.1GA_E3.3.2_Installer.exe、myEclipse6.5汉化包.rar、MyEclipse注册码.txt

2、安装 MyEclispeMe 开发插件

运行MyEclispe –>帮助–>Software Updates–>Find and Install –>搜索新部件

新建站点:http://eclipseme.org/updates/ (可能要翻翻哦),确定,全部勾选,安装,完毕。

3、安装 JDK

JDK6.0.21版本,如果找不到就先安装 jdk-6u20-windows-i586.exe 再打21补丁 JavaSetup6u21.exe。

4、安装 JavaME SDK

sun_java_me_sdk-3_0-win.exe

5、安装 WTK

WTK2.5.2_01版本,sun_java_wireless_toolkit-2.5.2_01-win.exe

MyEclispe–>首选项–>J2ME–>设备管理–>选择WTK目录–>refresh

(以上这些软件你就百度吧,不行就google,再不行必应)

注意:MyEclipse 编译的JAR包,很可能在虚拟机上安装不了。提示什么907啊,30的错误。

解决办法就是打开,JAR,编辑META-INF文件夹下的 MANIFEST.MF 文件,增加一行:

MIDlet-1: Test,,demo.LocationMIDlet  名字为Test,入口类为demo.LocationMIDlet

有的环境可能需要JAD包,相应的里面也要加上这一行。

二、支持JSR179的虚拟机

WM6.1上安装4EsmertecJbed_v20090217.5.1a_Chs.cab,狗狗搜,搜不到就找我要吧。

三、测试代码

package demo;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.location.Coordinates;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationProvider;
//import javax.microedition.location.QualifiedCoordinates;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class LocationMIDlet extends MIDlet implements CommandListener, Runnable
{
    private Display myDisplay;
    private Command okcmd;
    private Command ecmd;
    private Form form;
    private List myList;
    private boolean yes;

    public LocationMIDlet()
    {
        myDisplay = Display.getDisplay(this);
        myList = new List("测试真机是否支持 JSR179", List.IMPLICIT);
        okcmd = new Command("测试", Command.OK, 1);
        ecmd = new Command("退出", Command.OK, 1);
        form = new Form("GPS");
        String cellid=System.getProperty("CellID");
        if(cellid==null||"".equals(cellid)){
        	cellid=System.getProperty("Cell-ID");
        }
        if(cellid==null||"".equals(cellid)){
        	cellid=System.getProperty("CELLID");
        }
        if(cellid==null||"".equals(cellid)){
        	cellid=System.getProperty("CELL-ID");
        }
        form.append("CellID:"+cellid);
        form.append("JSR:"+System.getProperty("Version"));
        myList.addCommand(okcmd);
        form.addCommand(ecmd);
        form.setCommandListener(this);
        myList.setCommandListener(this);
    }
    protected void destroyApp(boolean arg0)
            throws MIDletStateChangeException {}
    protected void pauseApp(){}
    protected void startApp() throws MIDletStateChangeException
    {
        myDisplay.setCurrent(myList);
    }
    public void commandAction(Command arg0, Displayable arg1)
    {
    	if(arg0 == okcmd)
        {
            String version = System.getProperty("microedition.location.version");
            yes = (version != null && !version.equals(""));
            Thread t = new Thread(this);
            t.start();
        }
    	if(arg0 == ecmd)
        {
           this.notifyDestroyed();
        }
    }
    public void run()
    {
    	myDisplay.setCurrent(form);
        //测试真机是否支持 jsr179
        if(yes)
        {
            // Set criteria for selecting a location provider:
            // accurate to 500 meters horizontally
            // 设置精度
            Criteria myCriteria = new Criteria();
            myCriteria.setHorizontalAccuracy(500);

            double lat = 0;
            double lon = 0;

            // Get an instance of the provider
            // 找卫星,找服务
            try
            {
                LocationProvider myLocationProvider = LocationProvider.getInstance(myCriteria);

                // Request the location, setting a one-minute timeout
                // 请求位置,并设置超时时间
                Location myLocation = myLocationProvider.getLocation(5000);
                Thread.sleep(1000);
                Coordinates myCoordinates = myLocation.getQualifiedCoordinates();
                for(int i=0;i<10;i++){
                if(myCoordinates != null)
                {
                    // Use coordinate information
                    // 得到经纬度
                    lat = myCoordinates.getLatitude();
                    lon = myCoordinates.getLongitude();
                }

                form.append("真机支持JSR179,纬度坐标:" + String.valueOf(lat) + ",经度坐标:" + String.valueOf(lon));

                form.append("------------"+i);

                try{
                    Thread.sleep(1000);
                    }catch(Exception e){

                    }
                }
            }
            catch (LocationException e)
            {
            	form.append("LocationException 发生异常");
                e.printStackTrace();
            } catch (InterruptedException e)
            {
            	form.append("InterruptedException 发生异常");
                e.printStackTrace();
            }

        }
        //真机不支持 jsr179
        else
        {
        	form.append("真机不支持JSR179");

        }

    }

}

四、遗留问题

WM6.1手机系统运行JBED虚拟机上的Java ME软件,通过JSR179获取经纬度已实现。
(先运行WM上的GPS软件,后执行虚拟机里的测试代码)
两个问题:
1、室内等信号弱的地方无法定位;
2、JSR179是否需要WM上的程序进行GPS初始化待验证。
初步验证失败,貌似需要WM上先初始化GPS拨号找到卫星,虚拟机里程序才能读取数据,杯具。。。
再研究研究。。。