diff --git a/app/build.gradle b/app/build.gradle index 838e273..f7ccd64 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 + compileSdkVersion 28 useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "uk.org.openseizuredetector" - minSdkVersion 14 - targetSdkVersion 14 + minSdkVersion 19 + targetSdkVersion 28 + multiDexEnabled true } buildTypes { @@ -32,8 +33,8 @@ dependencies { testImplementation 'org.mockito:mockito-core:1.10.19' // Set this dependency if you want to use Hamcrest matching testImplementation 'org.hamcrest:hamcrest-library:1.1' - implementation 'com.android.support:appcompat-v7:22.2.1' - implementation 'com.android.support:support-v4:22.2.1' + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support:support-v4:28.0.0' //compile files('libs/JTransforms-3.1-with-dependencies.jar') implementation 'org.apache.commons:commons-math3:3.6.1' // google play services used for location finding for SMS alerts. diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index acce3c6..d13dd84 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index aba4a1e..c159b28 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -28,12 +28,10 @@ package uk.org.openseizuredetector; import java.text.DecimalFormat; import java.text.NumberFormat; -import java.util.Map; - -import fi.iki.elonen.NanoHTTPD; import android.app.ActivityManager; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -42,29 +40,24 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.res.AssetManager; import android.content.SharedPreferences; -import android.graphics.drawable.Drawable; import android.location.Location; import android.media.AudioManager; -import android.media.RingtoneManager; import android.media.ToneGenerator; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; +import android.os.Build; import android.os.CountDownTimer; -import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; import android.os.Binder; import android.os.IBinder; -import android.os.Looper; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.telephony.SmsManager; -import android.location.Location; import android.util.Log; import android.widget.Toast; @@ -72,13 +65,9 @@ import java.util.Timer; import java.util.TimerTask; import java.io.*; import java.util.*; -import java.util.StringTokenizer; import android.text.format.Time; -import org.json.JSONObject; -import org.json.JSONArray; - /** * Based on example at: @@ -89,9 +78,12 @@ import org.json.JSONArray; public class SdServer extends Service implements SdDataReceiver, SdLocationReceiver { // Notification ID private int NOTIFICATION_ID = 1; + private String mNotChId = "OSD Notification Channel"; + private CharSequence mNotChName = "OSD Notification Chennel"; + private String mNotChDesc = "OSD Notification Channel Description"; private NotificationManager mNM; - + private NotificationCompat.Builder mNotificationBuilder; private SdWebServer webServer = null; private final static String TAG = "SdServer"; private Timer dataLogTimer = null; @@ -151,7 +143,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei mToneGenerator = new ToneGenerator(AudioManager.STREAM_ALARM, 100); } - @Override public IBinder onBind(Intent intent) { Log.v(TAG, "sdServer.onBind()"); @@ -237,6 +228,18 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei mUtil.writeToSysLogFile("SdServer.onStartCommand() - starting SdDataSource"); mSdDataSource.start(); + // Initialise Notification channel for API level 26 and over + // from https://stackoverflow.com/questions/44443690/notificationcompat-with-api-26 + mNM= (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationBuilder = new NotificationCompat.Builder(this,mNotChId); + if (Build.VERSION.SDK_INT >= 26) { + NotificationChannel channel = new NotificationChannel(mNotChId, + mNotChName, + NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription(mNotChDesc); + mNM.createNotificationChannel(channel); + } + // Display a notification icon in the status bar of the phone to // show the service is running. @@ -372,16 +375,16 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this); - Notification notification = builder.setContentIntent(contentIntent) + Notification notification = mNotificationBuilder.setContentIntent(contentIntent) .setSmallIcon(iconId) + .setColor(0xff000000) .setTicker("OpenSeizureDetector") .setAutoCancel(false) .setContentTitle("OpenSeizureDetector") .setContentText(mSdDataSourceName + " Data Source") + .setOnlyAlertOnce(true) .build(); - mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); } diff --git a/app/src/main/res/drawable/star_of_life_24x24.png b/app/src/main/res/drawable/star_of_life_24x24.png index 0f4cdc1..1fef3d8 100644 Binary files a/app/src/main/res/drawable/star_of_life_24x24.png and b/app/src/main/res/drawable/star_of_life_24x24.png differ