Android Open Source - pyneo-wirelesslocation Cell A P I2






From Project

Back to project page pyneo-wirelesslocation.

License

The source code is released under:

GNU General Public License

If you think the Android project pyneo-wirelesslocation 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

package org.pyneo.android.cellapi;
// w w w.j  a va2 s . c o m
import android.util.Log;

import org.json.simple.JSONArray;
import org.json.simple.JSONValue;
import org.pyneo.android.TheDictionary;
import org.pyneo.android.TheList;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class CellAPI2 {
  private static final String TAG = CellAPI2.class.getName();
  private static boolean DEBUG = false;
  static { DEBUG = Log.isLoggable("org.pyneo.android", Log.DEBUG); }

  private static final String rid = "pyneo";
  private static final String url = "https://cellsit.vfnet.de/cellapi/v2/_/" + rid;
  private static final String secret = "aN3Peiv6";
  private static final Random random = new Random();

  static public TheList retrieveLocation(TheDictionary meta, TheList list, String resolve) throws Exception {
    if (DEBUG) Log.d(TAG, "retrieveLocation: retrieve list=" + list);
    TheList ret = null;
    Map<String,TheDictionary> map = new HashMap<String,TheDictionary>();
    String correlation_id = Long.toString(random.nextLong());
    meta.put("version", 2);
    meta.put("user", rid);
    meta.put("resolve", resolve);
    list.add(meta);
    if (DEBUG) Log.d(TAG, "retrieveLocation: request list=" + list);
    java.net.HttpURLConnection connection = (java.net.HttpURLConnection)new java.net.URL(url).openConnection();
    try {
      connection.setUseCaches(false);
      connection.setDoOutput(true);
      connection.setDoInput(true);
      connection.setReadTimeout(5000);
      connection.setRequestProperty("Content-Type", "text/json");
      connection.setRequestProperty("X-Correlation-Id", correlation_id);
      connection.setRequestMethod("POST");
      java.io.Writer out = new java.io.OutputStreamWriter(connection.getOutputStream());
      try {
        list.writeJSONString(out);
      }
      finally {
        out.flush();
        out.close();
      }
      int httpResponseCode = connection.getResponseCode();
      if (DEBUG) Log.d(TAG, "retrieveLocation: httpResponseCode=" + httpResponseCode);
      if (httpResponseCode != 200) {
        throw new Exception("httpResponseCode=" + httpResponseCode);
      }
      java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
      try {
        Object obj = JSONValue.parseWithException(in);
        if (DEBUG) Log.d(TAG, "retrieveLocation: response obj=" + obj);
        ret = new TheList((JSONArray)obj);
      }
      finally {
        in.close();
      }
      if (DEBUG) Log.d(TAG, "retrieveLocation: ret=" + ret);
    }
    finally {
      try { connection.disconnect(); } catch (Exception ignore) { }
    }
    if ("single".equals(resolve)) {
      list = ret;
    }
    else {
      for (TheDictionary entry: ret) {
        map.put(entry.getIdent(), entry);
      }
      for (TheDictionary entry: list) {
        TheDictionary r = map.get(entry.getIdent());
        entry.putAll(r);
      }
    }
    return list;
  }
}




Java Source Code List

android.location.GeocoderParams.java
android.location.LocationRequest.java
android.net.NetworkInfo.java
android.os.WorkSource.java
com.android.internal.location.ProviderProperties.java
com.android.internal.location.ProviderRequest.java
com.google.android.location.NetworkLocationService.java
com.google.android.location.geocode.GeocodeService.java
com.google.android.location.internal.server.GoogleLocationService.java
com.google.android.location.internal.server.NetworkLocationService.java
com.google.android.location.network.NetworkLocationService.java
internal.com.android.location.provider.GeocodeProvider.java
internal.com.android.location.provider.LocationProviderBase.java
internal.com.android.location.provider.LocationProvider.java
internal.com.android.location.provider.LocationRequestUnbundled.java
internal.com.android.location.provider.ProviderPropertiesUnbundled.java
internal.com.android.location.provider.ProviderRequestUnbundled.java
org.pyneo.android.TheDictionary.java
org.pyneo.android.TheList.java
org.pyneo.android.cellapi.CellAPI2.java
org.pyneo.android.wirelessid.CellIdPre17API.java
org.pyneo.android.wirelessid.CellId.java
org.pyneo.android.wirelessid.Meta.java
org.pyneo.android.wirelessid.Satellite.java
org.pyneo.android.wirelessid.WifiId.java
org.pyneo.wirelesslocation.GeocodeProvider.java
org.pyneo.wirelesslocation.MainService.java
org.pyneo.wirelesslocation.NetworkLocationProviderV1.java
org.pyneo.wirelesslocation.NetworkLocationProviderV2.java
org.pyneo.wirelesslocation.NetworkLocationProvider.java
org.pyneo.wirelesslocation.WirelessEnvListener.java