Modified notification to prevent more than one version of MainActivity being open at once. May not work completely!

This commit is contained in:
Graham Jones
2015-11-18 23:28:05 +00:00
parent c69ce006ce
commit 63604bc25b
2 changed files with 15 additions and 10 deletions

View File

@@ -47,6 +47,7 @@ import android.os.IBinder;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.NotificationCompat;
import android.telephony.SmsManager; import android.telephony.SmsManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@@ -231,15 +232,18 @@ public class SdServer extends Service implements SdDataReceiver {
*/ */
private void showNotification() { private void showNotification() {
Log.v(TAG, "showNotification()"); Log.v(TAG, "showNotification()");
CharSequence text = "OpenSeizureDetector Server Running"; Intent i = new Intent(getApplicationContext(),MainActivity.class);
Notification notification = i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
new Notification(R.drawable.star_of_life_24x24, text, PendingIntent contentIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
System.currentTimeMillis()); NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, Notification notification = builder.setContentIntent(contentIntent)
new Intent(this, MainActivity.class), 0); .setSmallIcon(R.drawable.star_of_life_24x24)
notification.setLatestEventInfo(this, "OpenSeizureDetector Server", .setTicker("OpenSeizureDetector")
text, contentIntent); .setAutoCancel(false)
notification.flags |= Notification.FLAG_NO_CLEAR; .setContentTitle("OpenSeizureDetector")
.setContentText("osdtext")
.build();
mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNM.notify(NOTIFICATION_ID, notification); mNM.notify(NOTIFICATION_ID, notification);
} }

View File

@@ -83,7 +83,7 @@ public class StartupActivity extends Activity {
mUtil.stopServer(); mUtil.stopServer();
} }
mUtil.startServer(); mUtil.startServer();
// Bind to the service. // Bind to the service.
mConnection = new SdServiceConnection(this); mConnection = new SdServiceConnection(this);
mUtil.bindToServer(this, mConnection); mUtil.bindToServer(this, mConnection);
@@ -190,6 +190,7 @@ public class StartupActivity extends Activity {
Intent intent = new Intent( Intent intent = new Intent(
getApplicationContext(), getApplicationContext(),
MainActivity.class); MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent); startActivity(intent);
finish(); finish();
} catch (Exception ex) { } catch (Exception ex) {