From 3b1d26bca71904e03567d5b5097a3c165dbb29aa Mon Sep 17 00:00:00 2001 From: Binabh Devkota Date: Wed, 26 Aug 2020 10:14:30 +0545 Subject: [PATCH 1/4] GPX Logger added --- .../android/formentry/backgroundlocation/GPXWriter.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java new file mode 100644 index 00000000000..19785349522 --- /dev/null +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java @@ -0,0 +1,4 @@ +package org.odk.collect.android.formentry.backgroundlocation; + +public class GPXWriter { +} From ec475274aa4a502114949eccbc906b7e874b865b Mon Sep 17 00:00:00 2001 From: Binabh Devkota Date: Wed, 26 Aug 2020 10:15:58 +0545 Subject: [PATCH 2/4] Gpxlogger working --- collect_app/src/main/AndroidManifest.xml | 1 + .../android/activities/GeoPolyActivity.java | 2 + .../android/activities/MainMenuActivity.java | 8 + .../BackgroundLocationHelper.java | 4 + .../BackgroundLocationManager.java | 4 + .../backgroundlocation/GPXWriter.java | 155 +++++++++++++++++- collect_app/src/main/res/menu/main_menu.xml | 4 + 7 files changed, 177 insertions(+), 1 deletion(-) diff --git a/collect_app/src/main/AndroidManifest.xml b/collect_app/src/main/AndroidManifest.xml index a2f7c15c6cf..b2b4e85be84 100644 --- a/collect_app/src/main/AndroidManifest.xml +++ b/collect_app/src/main/AndroidManifest.xml @@ -280,6 +280,7 @@ the specific language governing permissions and limitations under the License. + diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/GeoPolyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/GeoPolyActivity.java index d046b1dbf5c..7aa73ef2992 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/GeoPolyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/GeoPolyActivity.java @@ -17,6 +17,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.view.Window; import android.widget.Button; @@ -419,6 +420,7 @@ private void recordPoint() { MapPoint point = map.getGpsLocation(); if (point != null && isLocationAcceptable(point)) { map.appendPointToPoly(featureId, point); + // Log.i("MyLocation",point.toString()); updateUi(); } } diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java index 4225cbeace9..651097156e9 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java @@ -44,6 +44,7 @@ import org.odk.collect.android.configure.SettingsImporter; import org.odk.collect.android.configure.qr.QRCodeTabsActivity; import org.odk.collect.android.dao.InstancesDao; +import org.odk.collect.android.formentry.backgroundlocation.GPXWriter; import org.odk.collect.android.injection.DaggerUtils; import org.odk.collect.android.preferences.AdminKeys; import org.odk.collect.android.preferences.AdminPasswordDialogFragment; @@ -344,6 +345,13 @@ public boolean onOptionsItemSelected(MenuItem item) { startActivity(new Intent(this, AdminPreferencesActivity.class)); } return true; + case R.id.menu_start_log: + if(GPXWriter.isServiceRunning){ + stopService(new Intent(this, GPXWriter.class)); + }else { + startService(new Intent(this, GPXWriter.class)); + } + return true; } return super.onOptionsItemSelected(item); } diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationHelper.java b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationHelper.java index fa5b49bfb3f..ff711c2f9da 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationHelper.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationHelper.java @@ -1,6 +1,8 @@ package org.odk.collect.android.formentry.backgroundlocation; import android.location.Location; +import android.util.Log; +import android.widget.Toast; import org.odk.collect.android.application.Collect; import org.odk.collect.android.formentry.audit.AuditConfig; @@ -85,6 +87,8 @@ void logAuditEvent(AuditEvent.AuditEventType eventType) { * Precondition: the global form controller has been initialized. */ void provideLocationToAuditLogger(Location location) { + Log.i("MyLocation",location.toString()); + // Toast.makeText(Collect.getInstance().getApplicationContext(),"This is a message displayed in a Toast",Toast.LENGTH_SHORT).show(); Collect.getInstance().getFormController().getAuditEventLogger().addLocation(location); } } diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationManager.java b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationManager.java index 2614cf27bbd..3bb1f0270a2 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationManager.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/BackgroundLocationManager.java @@ -1,6 +1,7 @@ package org.odk.collect.android.formentry.backgroundlocation; import android.location.Location; +import android.util.Log; import androidx.annotation.NonNull; @@ -12,6 +13,8 @@ import org.odk.collect.android.formentry.audit.AuditEvent; import org.odk.collect.android.logic.actions.setgeopoint.CollectSetGeopointAction; +import timber.log.Timber; + /** * Manages background location for the location audit logging and odk:setgeopoint action features. * Provides precondition checking and user feedback for both features. @@ -242,6 +245,7 @@ private void stopLocationRequests() { public void onLocationChanged(Location location) { switch (currentState) { case RECEIVING_LOCATIONS: + Log.i("MyLocation",location.toString()); helper.provideLocationToAuditLogger(location); } } diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java index 19785349522..b35b08851be 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java @@ -1,4 +1,157 @@ package org.odk.collect.android.formentry.backgroundlocation; -public class GPXWriter { +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.location.Location; +import android.location.LocationManager; +import android.os.Bundle; +import android.os.IBinder; +import android.util.Log; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class GPXWriter extends Service { + public static boolean isServiceRunning = false; + private LocationManager mLocationManager = null; + private static final String TAG = "GPXWRITER"; + private static final int LOCATION_INTERVAL = 1000; + private static final float LOCATION_DISTANCE = 10f; + private FileWriter writer; + private Date date = new Date(); + private SimpleDateFormat xmldatadateformatter = new SimpleDateFormat("yyyy-MM-dd"); + private SimpleDateFormat xmldatatimeformatter = new SimpleDateFormat("HH:mm:ss"); + private String fileheader = "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " ODK Data Collector\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Example GPX Document\n" + + " "; + private String filefooter = "\n" + + " \n" + + ""; + + private class LocationListener implements android.location.LocationListener { + Location mLastLocation; + + public LocationListener(String provider) { + Log.e(TAG, "LocationListener " + provider); + mLastLocation = new Location(provider); + } + + @Override + public void onLocationChanged(Location location) { + Date pointDate = new Date(); + String message = "\n" + + " "+location.getAltitude()+"\n" + + " \n" + + " "; + Log.e(TAG, message); + try { + writer.append(message); + } catch (IOException e) { + e.printStackTrace(); + } + mLastLocation.set(location); + } + + @Override + public void onProviderDisabled(String provider) { + Log.e(TAG, "onProviderDisabled: " + provider); + } + + @Override + public void onProviderEnabled(String provider) { + Log.e(TAG, "onProviderEnabled: " + provider); + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + Log.e(TAG, "onStatusChanged: " + provider); + } + } + + LocationListener[] mLocationListeners = new LocationListener[]{ + new LocationListener(LocationManager.GPS_PROVIDER) + }; + + @Override + public IBinder onBind(Intent arg0) { + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.e(TAG, "onStartCommand"); + super.onStartCommand(intent, flags, startId); + isServiceRunning = true; + + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss"); + String filename= formatter.format(date)+".gpx"; + File dir = getApplicationContext().getExternalFilesDir("myDir"); + Log.e(TAG, dir.toString()); + File file = new File(dir, filename); + try { + writer = new FileWriter(file); + writer.append(fileheader); + } catch (IOException e) { + e.printStackTrace(); + } + return START_STICKY; + } + + @Override + public void onCreate() { + Log.e(TAG, "onCreate"); + initializeLocationManager(); + try { + mLocationManager.requestLocationUpdates( + LocationManager.GPS_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE, + mLocationListeners[0]); + } catch (java.lang.SecurityException ex) { + Log.i(TAG, "fail to request location update, ignore", ex); + } catch (IllegalArgumentException ex) { + Log.d(TAG, "gps provider does not exist " + ex.getMessage()); + } + } + + @Override + public void onDestroy() { + Log.e(TAG, "onDestroy"); + super.onDestroy(); + try { + writer.append(filefooter); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + isServiceRunning = false; + if (mLocationManager != null) { + for (int i = 0; i < mLocationListeners.length; i++) { + try { + mLocationManager.removeUpdates(mLocationListeners[i]); + } catch (Exception ex) { + Log.i(TAG, "fail to remove location listners, ignore", ex); + } + } + } + } + + private void initializeLocationManager() { + Log.e(TAG, "initializeLocationManager"); + if (mLocationManager == null) { + mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE); + } + } } diff --git a/collect_app/src/main/res/menu/main_menu.xml b/collect_app/src/main/res/menu/main_menu.xml index 24c14169192..ce57a7ee324 100644 --- a/collect_app/src/main/res/menu/main_menu.xml +++ b/collect_app/src/main/res/menu/main_menu.xml @@ -35,5 +35,9 @@ limitations under the License. android:id="@+id/menu_configure_qr_code" android:title="@string/configure_via_qr_code" app:showAsAction="never"/> + \ No newline at end of file From 68374a330cde6e8373366a831c54c864feec9fde Mon Sep 17 00:00:00 2001 From: Binabh Devkota Date: Wed, 26 Aug 2020 15:55:23 +0545 Subject: [PATCH 3/4] gpx stored in instances --- .../formentry/backgroundlocation/GPXWriter.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java index b35b08851be..1807e224b2f 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java @@ -9,6 +9,10 @@ import android.os.IBinder; import android.util.Log; +import org.odk.collect.android.application.Collect; +import org.odk.collect.android.storage.StoragePathProvider; +import org.odk.collect.android.storage.StorageSubdirectory; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -99,8 +103,12 @@ public int onStartCommand(Intent intent, int flags, int startId) { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss"); String filename= formatter.format(date)+".gpx"; File dir = getApplicationContext().getExternalFilesDir("myDir"); - Log.e(TAG, dir.toString()); - File file = new File(dir, filename); + StoragePathProvider storagePathProvider = new StoragePathProvider(); + String dir2 = storagePathProvider.getUnscopedStorageDirPath(StorageSubdirectory.INSTANCES)+"/GPSTraces"; + File folder = new File(dir2); + folder.mkdir(); + Log.e(TAG, folder.toString()); + File file = new File(folder, filename); try { writer = new FileWriter(file); writer.append(fileheader); From 5ab2cc42bdb889cc1650582903b14de48870731b Mon Sep 17 00:00:00 2001 From: Binabh Devkota Date: Mon, 31 Aug 2020 16:11:19 +0545 Subject: [PATCH 4/4] permissions added in fill blank form --- .../activities/FillBlankFormActivity.java | 25 +++++++++++ .../android/activities/FormEntryActivity.java | 1 + .../android/activities/MainMenuActivity.java | 6 +++ .../activities/SplashScreenActivity.java | 43 +++++++++++++++++++ .../backgroundlocation/GPXWriter.java | 23 ++++++---- .../android/storage/StorageSubdirectory.java | 1 + 6 files changed, 91 insertions(+), 8 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FillBlankFormActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FillBlankFormActivity.java index 9cadaa0fa71..569a9639f92 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FillBlankFormActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FillBlankFormActivity.java @@ -21,6 +21,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -35,6 +36,7 @@ import org.odk.collect.android.R; import org.odk.collect.android.adapters.FormListAdapter; import org.odk.collect.android.dao.FormsDao; +import org.odk.collect.android.formentry.backgroundlocation.GPXWriter; import org.odk.collect.android.formmanagement.BlankFormListMenuDelegate; import org.odk.collect.android.formmanagement.BlankFormsListViewModel; import org.odk.collect.android.injection.DaggerUtils; @@ -77,6 +79,9 @@ public class FillBlankFormActivity extends FormListActivity implements @Inject PreferencesProvider preferencesProvider; + @Inject + PermissionUtils permissionUtils; + @Inject Scheduler scheduler; @@ -90,6 +95,22 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.form_chooser_list); DaggerUtils.getComponent(this).inject(this); + Log.e("GPXWRITER","should ask location permission"); + permissionUtils.requestLocationPermissions(this, new PermissionListener() { + @Override + public void granted() { + if(GPXWriter.isServiceRunning){ + stopService(new Intent(getApplicationContext(),GPXWriter.class)); + }else { + startService(new Intent(getApplicationContext(), GPXWriter.class)); + } + } + + @Override + public void denied() { + finish(); + } + }); setTitle(getString(R.string.enter_data)); @@ -187,15 +208,19 @@ public Object onRetainCustomNonConfigurationInstance() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (MultiClickGuard.allowClick(getClass().getName())) { + + Log.e("ACTIVITY_CHECK","1"); // get uri to form long idFormsTable = listView.getAdapter().getItemId(position); Uri formUri = ContentUris.withAppendedId(FormsColumns.CONTENT_URI, idFormsTable); String action = getIntent().getAction(); if (Intent.ACTION_PICK.equals(action)) { + Log.e("ACTIVITY_CHECK","2"); // caller is waiting on a picked form setResult(RESULT_OK, new Intent().setData(formUri)); } else { + Log.e("ACTIVITY_CHECK","3"); // caller wants to view/edit a form, so launch formentryactivity Intent intent = new Intent(Intent.ACTION_EDIT, formUri); intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED); diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java index 2eff7028681..103bd257b40 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java @@ -29,6 +29,7 @@ import android.text.InputFilter; import android.text.TextWatcher; import android.util.DisplayMetrics; +import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector; diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java index 651097156e9..5459b5e73b6 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java @@ -14,6 +14,7 @@ package org.odk.collect.android.activities; +import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -46,6 +47,7 @@ import org.odk.collect.android.dao.InstancesDao; import org.odk.collect.android.formentry.backgroundlocation.GPXWriter; import org.odk.collect.android.injection.DaggerUtils; +import org.odk.collect.android.listeners.PermissionListener; import org.odk.collect.android.preferences.AdminKeys; import org.odk.collect.android.preferences.AdminPasswordDialogFragment; import org.odk.collect.android.preferences.AdminPasswordDialogFragment.Action; @@ -63,6 +65,7 @@ import org.odk.collect.android.utilities.ApplicationConstants; import org.odk.collect.android.utilities.DialogUtils; import org.odk.collect.android.utilities.MultiClickGuard; +import org.odk.collect.android.utilities.PermissionUtils; import org.odk.collect.android.utilities.PlayServicesChecker; import org.odk.collect.android.utilities.ToastUtils; import org.odk.collect.material.MaterialBanner; @@ -128,6 +131,8 @@ public class MainMenuActivity extends CollectAbstractActivity implements AdminPa @Inject SettingsImporter settingsImporter; + + @Inject MainMenuViewModel.Factory viewModelFactory; private MainMenuViewModel viewModel; @@ -346,6 +351,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } return true; case R.id.menu_start_log: + if(GPXWriter.isServiceRunning){ stopService(new Intent(this, GPXWriter.class)); }else { diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/SplashScreenActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/SplashScreenActivity.java index f7b1985cc47..c30f40a28b5 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/SplashScreenActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/SplashScreenActivity.java @@ -66,6 +66,34 @@ public class SplashScreenActivity extends Activity { @Inject GeneralSharedPreferences generalSharedPreferences; + private void checkforLocationPermission(){ + permissionUtils.requestLocationPermissions(this, new PermissionListener() { + @Override + public void granted() {} + + @Override + public void denied() { + } + }); + } + + private boolean checkforStoragePermission(){ + final boolean[] result = {false}; + permissionUtils.requestStoragePermissions(this, new PermissionListener() { + @Override + public void granted() { + result[0] = true; + } + + @Override + public void denied() { + // The activity has to finish because ODK Collect cannot function without these permissions. + result[0] = false; + } + }); + return result[0]; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -73,6 +101,20 @@ public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); DaggerUtils.getComponent(this).inject(this); +// if( checkforLocationPermission() && checkforStoragePermission()){ +// try { +// new StorageInitializer().createOdkDirsOnStorage(); +// } catch (RuntimeException e) { +// DialogUtils.showDialog(DialogUtils.createErrorDialog(SplashScreenActivity.this, +// e.getMessage(), EXIT), SplashScreenActivity.this); +// return; +// } +// +// init(); +// }else{ +// finish(); +// } + permissionUtils.requestStoragePermissions(this, new PermissionListener() { @Override public void granted() { @@ -94,6 +136,7 @@ public void denied() { finish(); } }); + } private void init() { diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java index 1807e224b2f..8e075d7ffcb 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/backgroundlocation/GPXWriter.java @@ -1,5 +1,6 @@ package org.odk.collect.android.formentry.backgroundlocation; +import android.app.Activity; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -8,10 +9,13 @@ import android.os.Bundle; import android.os.IBinder; import android.util.Log; +import android.widget.Toast; import org.odk.collect.android.application.Collect; +import org.odk.collect.android.listeners.PermissionListener; import org.odk.collect.android.storage.StoragePathProvider; import org.odk.collect.android.storage.StorageSubdirectory; +import org.odk.collect.android.utilities.PermissionUtils; import java.io.File; import java.io.FileWriter; @@ -26,6 +30,7 @@ public class GPXWriter extends Service { private static final int LOCATION_INTERVAL = 1000; private static final float LOCATION_DISTANCE = 10f; private FileWriter writer; + private PermissionUtils myPermissions; private Date date = new Date(); private SimpleDateFormat xmldatadateformatter = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat xmldatatimeformatter = new SimpleDateFormat("HH:mm:ss"); @@ -104,7 +109,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { String filename= formatter.format(date)+".gpx"; File dir = getApplicationContext().getExternalFilesDir("myDir"); StoragePathProvider storagePathProvider = new StoragePathProvider(); - String dir2 = storagePathProvider.getUnscopedStorageDirPath(StorageSubdirectory.INSTANCES)+"/GPSTraces"; + String dir2 = storagePathProvider.getUnscopedStorageDirPath(StorageSubdirectory.GPS_TRACES); File folder = new File(dir2); folder.mkdir(); Log.e(TAG, folder.toString()); @@ -135,14 +140,15 @@ public void onCreate() { @Override public void onDestroy() { - Log.e(TAG, "onDestroy"); super.onDestroy(); - try { - writer.append(filefooter); - writer.flush(); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); + if(writer != null){ + try { + writer.append(filefooter); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } } isServiceRunning = false; if (mLocationManager != null) { @@ -154,6 +160,7 @@ public void onDestroy() { } } } + Log.e(TAG, "onDestroy"); } private void initializeLocationManager() { diff --git a/collect_app/src/main/java/org/odk/collect/android/storage/StorageSubdirectory.java b/collect_app/src/main/java/org/odk/collect/android/storage/StorageSubdirectory.java index 628250b5e48..93766f34efc 100644 --- a/collect_app/src/main/java/org/odk/collect/android/storage/StorageSubdirectory.java +++ b/collect_app/src/main/java/org/odk/collect/android/storage/StorageSubdirectory.java @@ -6,6 +6,7 @@ public enum StorageSubdirectory { CACHE(".cache"), METADATA("metadata"), LAYERS("layers"), + GPS_TRACES("GPSTraces"), SETTINGS("settings"); private String directoryName;