Android Open Source - Andriod-PC-GPSApplication Android Data Reader






From Project

Back to project page Andriod-PC-GPSApplication.

License

The source code is released under:

MIT License

If you think the Android project Andriod-PC-GPSApplication listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * //  www .  j av a  2s.co  m
 */
package com.dev.appxpress.gps.android_pc;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.dev.appxpress.gps.android_pc.data.handler.GPSDataHandler;

/**
 * @author NThusitha
 * 
 */
public class AndroidDataReader {

  private static final Logger log = Logger.getLogger(AndroidDataReader.class.getName());
  private final static int SERVER_PORT = 38000;
  private final static String EOD_FLAG = "END";
  private GPSDataHandler handler = new GPSDataHandler();
  

  public void doConnect() {

    try {
      Socket client = new Socket("localhost", SERVER_PORT);
      
      log.log(Level.FINER, "opened connection to android device");
      
      //no need to using writer for now.
      PrintWriter writer = new PrintWriter(client.getOutputStream());
      
      
      BufferedReader buffReader = new BufferedReader(
          new InputStreamReader(client.getInputStream()));
      
      try {
        Thread.sleep(3000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      
      if (buffReader.ready()) {

        //StringBuffer dataBuff = new StringBuffer();

        String input;
        while ((input = buffReader.readLine()) != null) {
          if(input.contains(EOD_FLAG)){
            break;
          }
          //dataBuff.append(input);
          //dataBuff.append("\n");
          
          log.log(Level.FINER, "reading line {0}", input);
          handler.readData(input);
          //tempBuff.add(input);
          
        }

      //  System.out.print(dataBuff.toString());

      }else{
        log.log(Level.FINER, "device is not ready");
      }

    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

  }
  
  
  
  
  
  
}




Java Source Code List

com.dev.appxpress.gps.android_pc.AndroidDataReader.java
com.dev.appxpress.gps.android_pc.AndroidPCClientLauncher.java
com.dev.appxpress.gps.android_pc.data.handler.GPSDataHandler.java
com.dev.appxpress.gps.android_pc.domain.GPSAware.java
com.dev.appxpress.gps.android_pc.domain.GPSWayPoint.java
com.dev.appxpress.gps.android_pc.runtime.exec.PortForwarder.java
com.dev.appxpress.gps.android_pc.util.DateTimeUtil.java
com.dev.appxpress.gps.android_pc.util.PrintManager.java
com.example.appxgpsmodule.Globals.java
com.example.appxgpsmodule.Loaded.java
com.example.appxgpsmodule.Start.java
com.example.appxgpsmodule.storage.ExternalStorageReader.java