Converted to target SDK Level 28 - had to change how we did notifications, and specify a style to get back to black background. Still a problem with the 'ok' notification not displaying properly - background showing white for some reason.

This commit is contained in:
Graham Jones
2019-01-05 23:10:55 +00:00
parent fa9ad87985
commit 5157efcdac
4 changed files with 28 additions and 23 deletions

View File

@@ -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.

View File

@@ -24,6 +24,7 @@
<application
android:theme="@style/Theme.AppCompat"
android:icon="@drawable/star_of_life_48x48"
android:label="@string/app_name">
<activity android:name=".StartupActivity">

View File

@@ -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);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 B

After

Width:  |  Height:  |  Size: 210 B