示例#1
0
    @Override
    public void onReceive(Context context, Intent intent) {

      if (isConnected(context)) {
        try {
          Log.i("Connectivity Status", "Is connected");

          Set<String> files = filesToSync.keySet();

          for (String s : files) {
            if (filesToSync.get(s)) {
              FileInputStream fis = openFileInput(s);
              InputStreamReader isr = new InputStreamReader(fis);
              BufferedReader br = new BufferedReader(isr);

              StringBuilder total = new StringBuilder();
              String line;
              while ((line = br.readLine()) != null) {
                total.append(line);
              }

              Request.send_GPX(total.toString());
            }
          }

        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
示例#2
0
  public void saveCurrentRoute(View view) {

    if (GPS_captureStarted) {
      Log.w("Saving Route", "Can't Save, tracking not paused");
      return;
    }

    Element metadata = gpx_document.createElement("metadata");
    Element filename = gpx_document.createElement("name");
    Element author = gpx_document.createElement("author");
    Element trackName = gpx_document.createElement("name");

    String fn = "TestFile";
    String tn = "TestTrack";
    String auth = "Username";

    filename.appendChild(gpx_document.createTextNode(fn));
    author.appendChild(gpx_document.createTextNode(auth));
    trackName.appendChild(gpx_document.createTextNode(tn));

    track.appendChild(trackName);
    metadata.appendChild(filename);
    metadata.appendChild(author);
    rootElement.appendChild(metadata);

    try {

      ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      boolean isConnected = activeNetwork != null && activeNetwork.isConnected();

      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      DOMSource source = new DOMSource(gpx_document);
      StreamResult result;
      if (isConnected) {
        result = new StreamResult(new StringWriter());
        transformer.transform(source, result);
        String gpx = result.getWriter().toString();
        Request.send_GPX(gpx);
      } else {
        FileOutputStream stream = openFileOutput(fn + ".gpx", MODE_PRIVATE);
        result = new StreamResult(stream);
        transformer.transform(source, result);

        Log.i("writing file", "success");
        filesToSync.put(fn + ".gpx", true);
      }

    } catch (TransformerConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }