-
-
Notifications
You must be signed in to change notification settings - Fork 739
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 all commits
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,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<String> missingPermissions = new HashSet<>(); | ||
|
@@ -255,6 +275,9 @@ 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); | ||
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); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,5 @@ | |
<string name="status_connectivity_change">Connectivity change</string> | ||
<string name="hidden_app_name">Device Settings</string> | ||
<string name="hidden_alert">The app has been hidden. To open it again please dial 8722227 (TRACCAR).</string> | ||
<string name="prompt_location_service">Enable location service to find current location. Click OK to go to.</string> | ||
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 use some better wording. Something like:
|
||
</resources> |
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.
Still hardcoded string here.