diff --git a/app/src/main/java/org/traccar/client/MainActivity.java b/app/src/main/java/org/traccar/client/MainActivity.java index 5c891a7c..af41accc 100644 --- a/app/src/main/java/org/traccar/client/MainActivity.java +++ b/app/src/main/java/org/traccar/client/MainActivity.java @@ -16,14 +16,17 @@ package org.traccar.client; import android.Manifest; +import android.app.Activity; import android.app.AlarmManager; import android.app.AlertDialog; import android.app.PendingIntent; import android.content.ComponentName; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; @@ -32,6 +35,8 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceManager; import android.preference.TwoStatePreference; +import android.provider.Settings; +import android.text.TextUtils; import android.util.Log; import android.util.Patterns; import android.view.Menu; @@ -60,6 +65,7 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen private AlarmManager alarmManager; private PendingIntent alarmIntent; + private Object message; @Override public void onCreate(Bundle savedInstanceState) { @@ -230,6 +236,20 @@ private void initPreferences() { findPreference(KEY_DEVICE).setSummary(sharedPreferences.getString(KEY_DEVICE, null)); } + private void promptForEnablingLocationService(final Activity activity) + { + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setMessage(R.string.prompt_location_service) + .setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface d, int id) { + activity.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); + d.dismiss(); + } + }); + builder.create().show(); + } + private void startTrackingService(boolean checkPermission, boolean permission) { if (checkPermission) { Set missingPermissions = new HashSet<>(); @@ -255,6 +275,9 @@ private void startTrackingService(boolean checkPermission, boolean permission) { startService(new Intent(this, TrackingService.class)); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 15000, 15000, alarmIntent); + if (TextUtils.isEmpty(Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED))) { + promptForEnablingLocationService(this); + } } else { sharedPreferences.edit().putBoolean(KEY_STATUS, false).commit(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { @@ -286,5 +309,4 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in startTrackingService(false, granted); } } - } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4e71662c..87de62e7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,4 +44,5 @@ Connectivity change Device Settings The app has been hidden. To open it again please dial 8722227 (TRACCAR). + Enable location service to find current location. Click OK to go to.