gps2sms----Symbian s60 3 rd FP1
用java写了个获取GPS信息然后给指定号码发送的小程序,运行在自己手机(Symbian s60 3 rd FP1)上,记录下开发过程。
一、下载安装eclipse
二、利用eclipse的Install new software功能安装MTJ(Mobile Tools for Java ),链接为http://download.eclipse.org/mtj/updates/1.1.1/stable/
三、下载安装jre1.5.0
四、下载安装Symbian s60 3 rd FP1 SDK
附代码
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
import javax.microedition.io.*;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
class sendThread extends Thread {
public void send(String phone, String content) {
try {
String addr = "sms://" + phone;
MessageConnection conn = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(content);
conn.send(msg);
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
class getLocation
{
public void open(final String url)
{
Thread th = new Thread()
{
public void run()
{
try
{
sendThread sms = new sendThread();
HttpConnection con = (HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
DataInputStream in = con.openDataInputStream();
String content="";
int input;
while ((input = in.read()) != -1)
{
content = content + (char)input;
}
content = new String(content.getBytes(),"GB2312");
gps2sms.f.append("P: " + content);
sms.send("+8615912345678", content);
in.close();
con.close();
}
catch (IOException e)
{}
}
};
th.start();
}
}
public class gps2sms extends MIDlet implements CommandListener
{
public static Form f = new Form("gps2sms");
Command Exit = new Command("Exit", Command.EXIT, 0);
public gps2sms()
{
}
public void startApp()
{
getLocation getLocation = new getLocation();
f.append("Getting...\n");
f.addCommand(Exit);
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
try
{
Criteria c = new Criteria();
c.setHorizontalAccuracy(500);
c.setVerticalAccuracy(500);
LocationProvider lp = LocationProvider.getInstance(c);
Location loc = lp.getLocation(60);
Coordinates qc = loc.getQualifiedCoordinates();
f.append("H: " + qc.getAltitude()+"\n");
f.append("B: " + qc.getLatitude()+"\n");
f.append("L: " + qc.getLongitude()+"\n");
getLocation.open("http://www.anttna.com/gps2addr/gps2addr.php?lat="+qc.getLatitude()+"&lon="+qc.getLongitude());
}
catch (Exception e)
{
f.append("Exception: " + e);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean destroy)
{
}
public void commandAction(Command c, Displayable s)
{
if (c == Exit)
{
destroyApp(true);
notifyDestroyed();
}
}
}
程序每次运行,手机会提示是否允许应用程序xxx,而且没有总是允许的选项,很不方便,于是顺手XX了手机的java权限,步骤如下:
一、XX手机
二、下载“通用文件到C盘补丁(C2Z)”
三、将z:\sys\bin\EFSrv.dll复制出来,和c2z.exe放在同一文件夹下,运行c2z.exe,生成1个补丁文件rc2z.rmp,复制到手机存储卡:\patches目录(没有这个文件夹就自己新建),运行rompatcher,启用补丁并添加自启
四、下载java_permissions.zip,解压,得到两个xpf文件,复制到手机C:\System\data\midp2\security\policy
XX成功。
这时可以打开程序管理设置程序,如果程序管理打不开可以重启下手机。(文中提到软件烦请自行google)
另:每次打包jar后,都要手动在jad中添加MIDlet-1项,好麻烦,有没有解决办法?
#End#

浙公网安备 33010602011771号