Location notification tweeks
This commit is contained in:
parent
5aa6171c50
commit
a8e7ab6f06
@ -107,7 +107,9 @@ public class LocationUpdatesService extends Service {
|
|||||||
Log.i(TAG, "Requesting location updates. Every " + requestInterval + "ms with priority of " + priority);
|
Log.i(TAG, "Requesting location updates. Every " + requestInterval + "ms with priority of " + priority);
|
||||||
mLocationRequest.setPriority(priority);
|
mLocationRequest.setPriority(priority);
|
||||||
mLocationRequest.setInterval(requestInterval);
|
mLocationRequest.setInterval(requestInterval);
|
||||||
mLocationRequest.setFastestInterval(requestInterval);
|
if (priority == 102 && requestInterval > 60000) {
|
||||||
|
mLocationRequest.setFastestInterval(30000);
|
||||||
|
}
|
||||||
startForeground(LocationUtils.SERVICE_NOTIFICATION_ID, LocationUtils.getNotification(this, null, LocationUtils.SERVICE_NOTIFICATION_CHANNEL_ID));
|
startForeground(LocationUtils.SERVICE_NOTIFICATION_ID, LocationUtils.getNotification(this, null, LocationUtils.SERVICE_NOTIFICATION_CHANNEL_ID));
|
||||||
try {
|
try {
|
||||||
mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
||||||
|
@ -102,7 +102,9 @@ public class LocationUpdatesWorker extends ListenableWorker {
|
|||||||
int accuracy = LocationUtils.getLocationUpdatesPriority(getApplicationContext());
|
int accuracy = LocationUtils.getLocationUpdatesPriority(getApplicationContext());
|
||||||
locationRequest.setPriority(accuracy);
|
locationRequest.setPriority(accuracy);
|
||||||
locationRequest.setInterval(5000);
|
locationRequest.setInterval(5000);
|
||||||
locationRequest.setFastestInterval(1000);
|
if (accuracy == 102) {
|
||||||
|
locationRequest.setFastestInterval(1000);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
fusedLocationClient.requestLocationUpdates(locationRequest,
|
fusedLocationClient.requestLocationUpdates(locationRequest,
|
||||||
callback, Looper.myLooper());
|
callback, Looper.myLooper());
|
||||||
|
@ -46,7 +46,7 @@ class LocationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int getLocationUpdatesPriority(Context context) {
|
static int getLocationUpdatesPriority(Context context) {
|
||||||
return context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getInt(KEY_LOCATION_UPDATE_PRIORITY, 102);
|
return context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getInt(KEY_LOCATION_UPDATE_PRIORITY, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean showNotification(Context context) {
|
static boolean showNotification(Context context) {
|
||||||
@ -69,15 +69,6 @@ class LocationUtils {
|
|||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getLocationText(Location location) {
|
|
||||||
return location == null ? "Accuracy: unknown" :
|
|
||||||
"Accuracy: " + location.getAccuracy();
|
|
||||||
}
|
|
||||||
|
|
||||||
static String getLocationTitle(Location location) {
|
|
||||||
return location == null ? "Requesting location..." : "Location updated at " + DateFormat.getDateTimeInstance().format(new Date(location.getTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void startService(Context context) {
|
static void startService(Context context) {
|
||||||
Intent myService = new Intent(context, LocationUpdatesService.class);
|
Intent myService = new Intent(context, LocationUpdatesService.class);
|
||||||
context.startService(myService);
|
context.startService(myService);
|
||||||
@ -93,19 +84,24 @@ class LocationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Notification getNotification(Context context, Location location, String channelId) {
|
static Notification getNotification(Context context, Location location, String channelId) {
|
||||||
CharSequence text = LocationUtils.getLocationText(location);
|
CharSequence title = "Location tracking";
|
||||||
|
CharSequence text = location == null ? "Accuracy: unknown" : "Accuracy: " + location.getAccuracy() + " m";
|
||||||
|
CharSequence bigText = location == null ? "Waiting for location..." : "Location updated at " + DateFormat.getDateTimeInstance().format(new Date(location.getTime())) +
|
||||||
|
System.getProperty("line.separator") + "Accuracy: " + location.getAccuracy() + " m" +
|
||||||
|
System.getProperty("line.separator") + "Location: " + location.getLatitude() + ", " + location.getLongitude();
|
||||||
|
|
||||||
PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0,
|
PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0,
|
||||||
new Intent(context, MainActivity.class), 0);
|
new Intent(context, MainActivity.class), 0);
|
||||||
|
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
|
||||||
.addAction(R.drawable.blank_icon, "Open HA Client",
|
.setContentIntent(activityPendingIntent)
|
||||||
activityPendingIntent)
|
.setContentTitle(title)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
|
.setStyle(new NotificationCompat.BigTextStyle()
|
||||||
|
.bigText(bigText))
|
||||||
.setPriority(-1)
|
.setPriority(-1)
|
||||||
.setContentTitle(LocationUtils.getLocationTitle(location))
|
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setSmallIcon(R.drawable.mini_icon)
|
.setSmallIcon(R.drawable.mini_icon_location)
|
||||||
.setWhen(System.currentTimeMillis());
|
.setWhen(System.currentTimeMillis());
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
BIN
android/app/src/main/res/drawable/mini_icon_location.png
Normal file
BIN
android/app/src/main/res/drawable/mini_icon_location.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 571 B |
@ -13,10 +13,8 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
|
|
||||||
static const platform = const MethodChannel('com.keyboardcrumbs.hassclient/native');
|
static const platform = const MethodChannel('com.keyboardcrumbs.hassclient/native');
|
||||||
static final locationAccuracy = {
|
static final locationAccuracy = {
|
||||||
100: "Highest",
|
100: "High",
|
||||||
102: "Balanced (about 100 meters)",
|
102: "Balanced"
|
||||||
104: "Low (up to 10 kilometers)",
|
|
||||||
105: "Passive (last known location)",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Duration _locationInterval;
|
Duration _locationInterval;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: hass_client
|
name: hass_client
|
||||||
description: Home Assistant Android Client
|
description: Home Assistant Android Client
|
||||||
|
|
||||||
version: 1.3.0+1303
|
version: 1.3.0+1304
|
||||||
|
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
Reference in New Issue
Block a user