示例#1
0
  /**
   * Retrieve device information.
   *
   * @param code - Operation code.
   */
  public void getLocationInfo(String code) {
    double latitude;
    double longitude;
    JSONObject result = new JSONObject();
    GPSTracker gps = new GPSTracker(context);

    try {
      latitude = gps.getLatitude();
      longitude = gps.getLongitude();
      result.put(LOCATION_INFO_TAG_LATITUDE, latitude);
      result.put(LOCATION_INFO_TAG_LONGITUDE, longitude);
      resultBuilder.build(code, result);
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }
示例#2
0
  /**
   * Retrieve device information.
   *
   * @param code - Operation code.
   */
  public void getDeviceInfo(String code) {
    DeviceInfo deviceInfo = new DeviceInfo(context.getApplicationContext());
    DeviceState phoneState =
        DeviceStateFactory.getDeviceState(
            context.getApplicationContext(), deviceInfo.getSdkVersion());
    GPSTracker gps = new GPSTracker(context.getApplicationContext());
    JSONObject result = new JSONObject();
    JSONObject batteryInfo = new JSONObject();
    JSONObject internalMemoryInfo = new JSONObject();
    JSONObject externalMemoryInfo = new JSONObject();
    JSONObject locationInfo = new JSONObject();
    double latitude;
    double longitude;

    try {
      latitude = gps.getLatitude();
      longitude = gps.getLongitude();
      int batteryLevel = (int) Math.floor(phoneState.getBatteryLevel());
      batteryInfo.put(BATTERY_INFO_TAG_LEVEL, batteryLevel);

      internalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalInternalMemorySize());
      internalMemoryInfo.put(
          MEMORY_INFO_TAG_AVAILABLE, phoneState.getAvailableInternalMemorySize());
      externalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalExternalMemorySize());
      externalMemoryInfo.put(
          MEMORY_INFO_TAG_AVAILABLE, phoneState.getAvailableExternalMemorySize());
      locationInfo.put(LOCATION_INFO_TAG_LATITUDE, latitude);
      locationInfo.put(LOCATION_INFO_TAG_LONGITUDE, longitude);

      result.put(BATTERY_INFO_TAG, batteryInfo);
      result.put(MEMORY_INFO_TAG_INTERNAL, internalMemoryInfo);
      result.put(MEMORY_INFO_TAG_EXTERNAL, externalMemoryInfo);
      if (latitude != 0 && longitude != 0) {
        result.put(LOCATION_INFO_TAG, locationInfo);
      }
      result.put(NETWORK_OPERATOR_TAG, deviceInfo.getNetworkOperatorName());

      resultBuilder.build(code, result);

    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }