From a3b73fd4921983fda49f0efa485a894e1c87c5ba Mon Sep 17 00:00:00 2001 From: Herbert von Broeuschmeul Date: Tue, 26 Oct 2010 02:49:21 +0200 Subject: add notifications when service cannot be started * add notification when service cannot be started --- .../bluetooth/provider/BlueetoothGpsManager.java | 24 ++++++++++++++++------ .../provider/BluetoothGpsProviderService.java | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index ff94ac6..5f1860b 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -228,16 +228,20 @@ public class BlueetoothGpsManager { gpsSocket.connect(); // connection obtained so reset the number of connection try connected = true; + // reset eventual disabling cause +// setDisableReason(0); nbRetriesRemaining = 1+maxConnectionRetries ; notificationManager.cancel(R.string.connection_problem_notification_title); connectedGps = new ConnectedGps(gpsSocket); connectionAndReadingPool.execute(connectedGps); } +// } else if (! bluetoothAdapter.isEnabled()) { +// setDisableReason(R.string.msg_bluetooth_disabled); } } catch (IOException connectException) { // Unable to connect Log.e("BT test", "error while connecting to socket", connectException); - disable(R.string.msg_bluetooth_gps_unavaible); + // disable(R.string.msg_bluetooth_gps_unavaible); } finally { nbRetriesRemaining--; if (! connected) { @@ -271,10 +275,10 @@ public class BlueetoothGpsManager { connectionProblemNotification.number = 1 + maxConnectionRetries - nbRetriesRemaining; notificationManager.notify(R.string.connection_problem_notification_title, connectionProblemNotification); } else { - notificationManager.cancel(R.string.connection_problem_notification_title); - serviceStoppedNotification.when = System.currentTimeMillis(); - notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification); - disable(); +// notificationManager.cancel(R.string.connection_problem_notification_title); +// serviceStoppedNotification.when = System.currentTimeMillis(); +// notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification); + disable(R.string.msg_two_many_connection_problems); } } } @@ -285,6 +289,15 @@ public class BlueetoothGpsManager { } public synchronized void disable() { + notificationManager.cancel(R.string.connection_problem_notification_title); + if (getDisableReason() != 0){ + serviceStoppedNotification.when = System.currentTimeMillis(); + serviceStoppedNotification.setLatestEventInfo(appContext, + appContext.getString(R.string.service_closed_because_connection_problem_notification_title), + appContext.getString(R.string.service_closed_because_connection_problem_notification, appContext.getString(getDisableReason())), + serviceStoppedNotification.contentIntent); + notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification); + } if (enabled){ enabled = false; if (gpsSocket != null){ @@ -298,7 +311,6 @@ public class BlueetoothGpsManager { disableMockLocationProvider(); notificationPool.shutdown(); connectionAndReadingPool.shutdown(); - notificationManager.cancel(R.string.connection_problem_notification_title); callingService.stopSelf(); } } diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java index 1b5c238..5146d1d 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java @@ -181,7 +181,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener gpsManager = null; if (manager != null){ if (manager.getDisableReason() != 0){ - toast.setText(manager.getDisableReason()); + toast.setText(getString(R.string.msg_gps_provider_stopped_by_problem, getString(manager.getDisableReason()))); toast.show(); } else { toast.setText(R.string.msg_gps_provider_stopped); -- cgit v1.1