-
-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display prompt for enabling GPS #252
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,12 @@ | |
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; | ||
|
@@ -32,6 +34,7 @@ | |
import android.preference.PreferenceActivity; | ||
import android.preference.PreferenceManager; | ||
import android.preference.TwoStatePreference; | ||
import android.provider.Settings; | ||
import android.util.Log; | ||
import android.util.Patterns; | ||
import android.view.Menu; | ||
|
@@ -230,6 +233,25 @@ private void initPreferences() { | |
findPreference(KEY_DEVICE).setSummary(sharedPreferences.getString(KEY_DEVICE, null)); | ||
} | ||
|
||
private void displayPromptForEnablingGPS( | ||
final Activity activity) | ||
{ | ||
final AlertDialog.Builder builder = new AlertDialog.Builder(activity); | ||
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a variable for this? |
||
final String message = "Enable location service to find current location. Click OK to go to."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use hardcoded strings. |
||
|
||
builder.setMessage(message) | ||
.setPositiveButton("OK", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still hardcoded string here. |
||
new DialogInterface.OnClickListener() { | ||
public void onClick(DialogInterface d, int id) { | ||
activity.startActivity(new Intent(action)); | ||
d.dismiss(); | ||
} | ||
}); | ||
|
||
builder.create().show(); | ||
} | ||
|
||
private void startTrackingService(boolean checkPermission, boolean permission) { | ||
if (checkPermission) { | ||
Set<String> missingPermissions = new HashSet<>(); | ||
|
@@ -255,6 +277,10 @@ private void startTrackingService(boolean checkPermission, boolean permission) { | |
startService(new Intent(this, TrackingService.class)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we wait till user enables providers before starting the service? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, because if user not enable providers, it will be useless. Traccar-client cannot update location and send it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You said yes, but you haven't fixed it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, I'm still trying but have not been successful. I try to use AsyncTask (https://developer.android.com/reference/android/os/AsyncTask.html) |
||
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, | ||
15000, 15000, alarmIntent); | ||
String locationProviders = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); | ||
if (locationProviders == null || locationProviders.equals("")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
displayPromptForEnablingGPS(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it called "GPS" when you check for all providers? |
||
} | ||
} else { | ||
sharedPreferences.edit().putBoolean(KEY_STATUS, false).commit(); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPS should be camel-cased.