diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5581da9..c5bc095 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,5 +1,6 @@ + payload) { if (prefs.getBoolean(Logger.LOGGER_LOCATION_ENABLED, Logger.LOGGER_LOCATION_ENABLED_DEFAULT)) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ) { - LocationManager lm = (LocationManager) this._context.getSystemService(Context.LOCATION_SERVICE); + if (ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + LocationManager lm = (LocationManager) this._context.getSystemService(Context.LOCATION_SERVICE); - Location lastLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); + Location lastLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); - Location backupLocation = null; + Location backupLocation = null; - if (lastLocation != null && now - lastLocation.getTime() > (1000 * 60 * 60)) { - backupLocation = lastLocation; + if (lastLocation != null && now - lastLocation.getTime() > (1000 * 60 * 60)) { + backupLocation = lastLocation; - lastLocation = null; - } + lastLocation = null; + } - if (lastLocation == null) - lastLocation = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + if (lastLocation == null) + lastLocation = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - if (lastLocation == null) - lastLocation = backupLocation; + if (lastLocation == null) + lastLocation = backupLocation; - if (lastLocation != null) { - payload.put(Logger.LATITUDE, lastLocation.getLatitude()); - payload.put(Logger.LONGITUDE, lastLocation.getLongitude()); - payload.put(Logger.ALTITUDE, lastLocation.getAltitude()); - payload.put(Logger.TIME_DRIFT, now - lastLocation.getTime()); + if (lastLocation != null) { + payload.put(Logger.LATITUDE, lastLocation.getLatitude()); + payload.put(Logger.LONGITUDE, lastLocation.getLongitude()); + payload.put(Logger.ALTITUDE, lastLocation.getAltitude()); + payload.put(Logger.TIME_DRIFT, now - lastLocation.getTime()); + } } } } @@ -482,7 +484,7 @@ public Response intercept(Chain chain) throws IOException { String payload = c.getString(c.getColumnIndex(LogContentProvider.APP_EVENT_PAYLOAD)); RequestBody formBody = new FormBody.Builder() - .add(Logger.JSON, payload.toString()) + .add(Logger.JSON, payload) .build(); Request request = new Request.Builder() @@ -679,7 +681,7 @@ private void setBoolean(String key, boolean value) Editor e = prefs.edit(); e.putBoolean(key, value); - e.commit(); + e.apply(); } public void setEnabled(boolean enabled) @@ -747,7 +749,7 @@ public void setUploadUri(Uri uri) Editor e = prefs.edit(); e.putString(Logger.LOGGER_URI, uri.toString()); - e.commit(); + e.apply(); } public void setUserAgent(String userAgent) @@ -756,7 +758,7 @@ public void setUserAgent(String userAgent) Editor e = prefs.edit(); e.putString(Logger.LOGGER_USER_AGENT, userAgent); - e.commit(); + e.apply(); } public Uri getUploadUri() @@ -775,7 +777,7 @@ public void setUploadInterval(long interval) Editor e = prefs.edit(); e.putLong(Logger.INTERVAL, interval); - e.commit(); + e.apply(); } public boolean postJsonContent(JSONObject content, Uri destination) diff --git a/src/edu/northwestern/cbits/anthracite/WiFiHelper.java b/src/edu/northwestern/cbits/anthracite/WiFiHelper.java old mode 100644 new mode 100755 index 4c7a048..bb10bec --- a/src/edu/northwestern/cbits/anthracite/WiFiHelper.java +++ b/src/edu/northwestern/cbits/anthracite/WiFiHelper.java @@ -15,8 +15,7 @@ public static boolean wifiAvailable(Context context) { if (now - WiFiHelper._lastWifiCheck > 10000) { WiFiHelper._lastWifiCheck = now; - WifiManager wifi = (WifiManager) context - .getSystemService(Context.WIFI_SERVICE); + WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifi.isWifiEnabled()) { WiFiHelper._wifiAvailable = true;