/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.util.*; import javax.microedition.io.*; import javax.bluetooth.*; import java.util.Vector; import javax.microedition.lcdui.*; import javax.microedition.location.*; import java.rmi.Remote; import javax.microedition.midlet.*; /** * @author r */ public class GPS extends MIDlet implements CommandListener { Command Exit = new Command("Refresh",Command.EXIT,0); Command send=new Command("send",Command.OK,1) ; Form f = new Form("GPS "); String msg; StreamConnectionNotifier notifier; StreamConnection conn; LocalDevice localDevice; ServiceRecord serviceRecord; InputStream input; OutputStream output; private static final UUID BTGPSSERVER = new UUID(0x1101); private boolean isInit; public void startApp() { try { boolean isBTReady = false; // create/get a local device localDevice = LocalDevice.getLocalDevice(); // set we are discoverable if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC)) { // Some implementations always return false, even if // setDiscoverable successful // throw new IOException("Can't set discoverable mode..."); } StringBuffer serverUrl = new StringBuffer("btspp://"); // indicate this is a server serverUrl.append("localhost").append(':'); // add the UUID to identify this service serverUrl.append(BTGPSSERVER.toString()); // add the name for our service serverUrl.append(";name=GPS SERVICE"); // request all of the client not to be authorized // some devices fail on authorize=true serverUrl.append(";authorize=false"); // create notifier now notifier = (StreamConnectionNotifier)Connector.open(serverUrl.toString()); // and remember the service record for the later updates serviceRecord = localDevice.getRecord(notifier); // and remember the service record for the later updates serviceRecord = localDevice.getRecord(notifier); f.append("Mining gps data \n"); f.addCommand(Exit); f.addCommand(send); f.setCommandListener(this); Display.getDisplay(this).setCurrent(f); Display.getDisplay(this).setCurrent(f); try { Criteria c=new Criteria(); c.setHorizontalAccuracy(1000); c.setVerticalAccuracy(1000); c.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH); LocationProvider lp=LocationProvider.getInstance(c); Location loc=lp.getLocation(60); QualifiedCoordinates qc=loc.getQualifiedCoordinates(); f.append("Alt: "+qc.getAltitude()); f.append("Lat: "+qc.getLatitude()); f.append("Long: "+qc.getLongitude()); msg="GPGGA"+qc.getAltitude(); msg=msg + "$"; msg=msg+qc.getLatitude(); msg=msg+qc.getLongitude(); output = conn.openOutputStream(); output.write(msg.length()); // length is 1 byte output.write(msg.getBytes()); output.close(); } catch(Exception e) { f.append("Alt : 0000\n"); f.append("Lat : 0000\n" ); f.append("Long: 0000\n"); f.append("Your GPS device has this error "+e); } }catch(Exception e) { f.append("error "+e); } } public void resumeMidlet() { } public void pauseApp() {this.pauseApp(); } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { if (c == Exit) { startApp(); } if(c==send) { f.append("System under Construction"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)