From 63604bc25b417d0ad69aeb2b2eb725d390b34298 Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Wed, 18 Nov 2015 23:28:05 +0000 Subject: [PATCH] Modified notification to prevent more than one version of MainActivity being open at once. May not work completely! --- .../uk/org/openseizuredetector/SdServer.java | 22 +++++++++++-------- .../openseizuredetector/StartupActivity.java | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 60b5c76..f99e943 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -47,6 +47,7 @@ import android.os.IBinder; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.preference.PreferenceManager; +import android.support.v7.app.NotificationCompat; import android.telephony.SmsManager; import android.util.Log; import android.widget.Toast; @@ -231,15 +232,18 @@ public class SdServer extends Service implements SdDataReceiver { */ private void showNotification() { Log.v(TAG, "showNotification()"); - CharSequence text = "OpenSeizureDetector Server Running"; - Notification notification = - new Notification(R.drawable.star_of_life_24x24, text, - System.currentTimeMillis()); - PendingIntent contentIntent = PendingIntent.getActivity(this, 0, - new Intent(this, MainActivity.class), 0); - notification.setLatestEventInfo(this, "OpenSeizureDetector Server", - text, contentIntent); - notification.flags |= Notification.FLAG_NO_CLEAR; + Intent i = new Intent(getApplicationContext(),MainActivity.class); + i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + PendingIntent contentIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT); + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + Notification notification = builder.setContentIntent(contentIntent) + .setSmallIcon(R.drawable.star_of_life_24x24) + .setTicker("OpenSeizureDetector") + .setAutoCancel(false) + .setContentTitle("OpenSeizureDetector") + .setContentText("osdtext") + .build(); + mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); } diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java index 6901f63..fd57b86 100644 --- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java @@ -83,7 +83,7 @@ public class StartupActivity extends Activity { mUtil.stopServer(); } mUtil.startServer(); - + // Bind to the service. mConnection = new SdServiceConnection(this); mUtil.bindToServer(this, mConnection); @@ -190,6 +190,7 @@ public class StartupActivity extends Activity { Intent intent = new Intent( getApplicationContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); finish(); } catch (Exception ex) {