Click here to Skip to main content
15,887,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have developed a j2me application it reads gps cordinates from the internal gps and i want to send this cordinates over bluetooth to a pc.here i have created a service but i cant sucessfully transfer the
code
Java
/*
 * 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");
           
             
    }
}
}
Posted
Updated 11-Apr-11 4:14am
v3
Comments
Manfred Rudolf Bihy 11-Apr-11 10:15am    
Edit: Added pre tags.
Sergey Alexandrovich Kryukov 11-Apr-11 12:41pm    
Where is the question?!
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900