Android Open Source - smartnavi Statistics






From Project

Back to project page smartnavi.

License

The source code is released under:

Apache License

If you think the Android project smartnavi 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 com.ilm.sandwich.tools;
//w ww  .  j a v  a 2 s. com
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;

import com.ilm.sandwich.Config;

import org.json.JSONObject;

import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * This class is fired when the app is finished.
 * Anonymous usage statistics will be sent to the backend.
 * No locations and no personal data are transmitted.
 * The uid is a random number which is set at each new installation.
 * Statistics are important to improve the app according to usage of the users.
 *
 * @author Christian Henke
 *         www.smartnavi-app.com
 */
public class Statistics {
    public Statistics() {

    }

    public void check(Context context) {
        SharedPreferences settings = context.getSharedPreferences(context.getPackageName() + "_preferences", Context.MODE_PRIVATE);
        if (settings.getBoolean("nutzdaten", true)) {
            sendStatistics(context, settings);
        }
    }

    public void sendStatistics(Context context, SharedPreferences settings) {

        SensorManager mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        String magnetName = "not existing";
        try {
            magnetName = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD).getName();
        } catch (Exception e) {
        }
        String aclName = "not existing";
        try {
            aclName = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER).getName();
        } catch (Exception e) {
        }
        String gyroName = "not existing";
        try {
            gyroName = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE).getName();
        } catch (Exception e) {
        }

        JSONObject usageData = new JSONObject();
        try {
            // status
            usageData.put("uid", settings.getString("uid", "0"));
            // device info
            usageData.put("deviceName", android.os.Build.DEVICE);
            usageData.put("productName", android.os.Build.PRODUCT);
            usageData.put("modelName", android.os.Build.MODEL);
            usageData.put("androidVersion", android.os.Build.VERSION.SDK_INT);
            // sensor info
            usageData.put("aclName", aclName);
            usageData.put("magnName", magnetName);
            usageData.put("gyroName", gyroName);

            usageData.put("meanAclFreq", (int) Config.meanAclFreq);
            usageData.put("meanMagnFreq", (int) Config.meanMagnFreq);

            usageData.put("mapSource", settings.getString("MapSource", "-"));
            int serviceUsage = 0;
            if (Config.backgroundServiceUsed) {
                serviceUsage = 1;
            }
            usageData.put("serviceUsage", serviceUsage);

            int autoCorrect = 0;
            if (settings.getBoolean("autocorrect", false)) {
                autoCorrect = 1;
            }
            usageData.put("autocorrect", autoCorrect);
            usageData.put("gpstimer", settings.getInt("gpstimer", 1));

            int time = (int) ((System.currentTimeMillis() - Config.startTime) / 1000);
            usageData.put("time", time);

            //Number of steps
            usageData.put("stepCounter", Core.stepCounter);
        } catch (Exception e) {
            if (Config.debugMode) {
                e.printStackTrace();
            }
        }
        if (Config.debugMode) {
            Log.i("Usage Data", usageData.toString());
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            new connectAndSend(usageData).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            new connectAndSend(usageData).execute();
        }
    }

    private class connectAndSend extends AsyncTask<Void, Void, Void> {
        private JSONObject usageData;

        private connectAndSend(JSONObject usageData) {
            this.usageData = usageData;
        }

        @Override
        protected Void doInBackground(Void... params) {
            // send Data to Server
            try {
                URL url = new URL(Config.API_URL);
                HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
                httpCon.setDoOutput(true);
                httpCon.setRequestMethod("PUT");
                httpCon.setRequestProperty("Content-Type", "application/json");
                OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
                out.write(usageData.toString());
                out.close();
                int respCode = httpCon.getResponseCode();
                if (Config.debugMode) {
                    Log.d("UsageData", "Server-Response: " + respCode);
                }
                httpCon.disconnect();
            } catch (Exception e) {
                if (Config.debugMode) {
                    e.printStackTrace();
                }
            }
            return null;
        }
    }


}




Java Source Code List

com.ilm.sandwich.BackgroundService.java
com.ilm.sandwich.BuildConfig.java
com.ilm.sandwich.Config.java
com.ilm.sandwich.GoogleMapActivity.java
com.ilm.sandwich.Info.java
com.ilm.sandwich.MySupportMapFragment.java
com.ilm.sandwich.OsmMapActivity.java
com.ilm.sandwich.Settings.java
com.ilm.sandwich.StartChooser.java
com.ilm.sandwich.TouchableWrapper.java
com.ilm.sandwich.tools.Core.java
com.ilm.sandwich.tools.HttpRequests.java
com.ilm.sandwich.tools.Locationer.java
com.ilm.sandwich.tools.MapDownload.java
com.ilm.sandwich.tools.MyItemizedOverlay.java
com.ilm.sandwich.tools.PlacesAutoComplete.java
com.ilm.sandwich.tools.PlacesTextSearch.java
com.ilm.sandwich.tools.Statistics.java
com.ilm.sandwich.tools.SuggestionsAdapter.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.cachemanager.CacheManager.java
org.osmdroid.bonuspack.clustering.GridMarkerClusterer.java
org.osmdroid.bonuspack.clustering.MarkerClusterer.java
org.osmdroid.bonuspack.clustering.StaticCluster.java
org.osmdroid.bonuspack.kml.ColorStyle.java
org.osmdroid.bonuspack.kml.IconStyle.java
org.osmdroid.bonuspack.kml.KmlDocument.java
org.osmdroid.bonuspack.kml.KmlFeature.java
org.osmdroid.bonuspack.kml.KmlFolder.java
org.osmdroid.bonuspack.kml.KmlGeometry.java
org.osmdroid.bonuspack.kml.KmlGroundOverlay.java
org.osmdroid.bonuspack.kml.KmlLineString.java
org.osmdroid.bonuspack.kml.KmlMultiGeometry.java
org.osmdroid.bonuspack.kml.KmlPlacemark.java
org.osmdroid.bonuspack.kml.KmlPoint.java
org.osmdroid.bonuspack.kml.KmlPolygon.java
org.osmdroid.bonuspack.kml.LineStyle.java
org.osmdroid.bonuspack.kml.Style.java
org.osmdroid.bonuspack.location.FlickrPOIProvider.java
org.osmdroid.bonuspack.location.GeoNamesPOIProvider.java
org.osmdroid.bonuspack.location.GeocoderGisgraphy.java
org.osmdroid.bonuspack.location.GeocoderNominatimOld.java
org.osmdroid.bonuspack.location.GeocoderNominatim.java
org.osmdroid.bonuspack.location.NominatimPOIProvider.java
org.osmdroid.bonuspack.location.POI.java
org.osmdroid.bonuspack.location.PicasaPOIProvider.java
org.osmdroid.bonuspack.mapsforge.GenericMapView.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileModuleProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileSource.java
org.osmdroid.bonuspack.overlays.DefaultInfoWindow.java
org.osmdroid.bonuspack.overlays.ExtendedOverlayItem.java
org.osmdroid.bonuspack.overlays.FolderOverlay.java
org.osmdroid.bonuspack.overlays.GroundOverlay.java
org.osmdroid.bonuspack.overlays.InfoWindow.java
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.java
org.osmdroid.bonuspack.overlays.MapEventsOverlay.java
org.osmdroid.bonuspack.overlays.MapEventsReceiver.java
org.osmdroid.bonuspack.overlays.MarkerInfoWindow.java
org.osmdroid.bonuspack.overlays.Marker.java
org.osmdroid.bonuspack.overlays.Polygon.java
org.osmdroid.bonuspack.overlays.Polyline.java
org.osmdroid.bonuspack.routing.GoogleRoadManager.java
org.osmdroid.bonuspack.routing.MapQuestRoadManager.java
org.osmdroid.bonuspack.routing.OSRMRoadManager.java
org.osmdroid.bonuspack.routing.RoadLeg.java
org.osmdroid.bonuspack.routing.RoadManager.java
org.osmdroid.bonuspack.routing.RoadNode.java
org.osmdroid.bonuspack.routing.Road.java
org.osmdroid.bonuspack.utils.BonusPackHelper.java
org.osmdroid.bonuspack.utils.DouglasPeuckerReducer.java
org.osmdroid.bonuspack.utils.HttpConnection.java
org.osmdroid.bonuspack.utils.PolylineEncoder.java
org.osmdroid.bonuspack.utils.WebImageCache.java