Skip to content

Commit

Permalink
DroidPlannerService: allow compatibility with SDK 28
Browse files Browse the repository at this point in the history
  • Loading branch information
HefnySco committed Sep 30, 2019
1 parent 6584feb commit 01d3448
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ClientLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def logLevelError = 6;
def logLevelAssert = 7;

android {
compileSdkVersion android_build_sdk_version
compileSdkVersion 28
buildToolsVersion android_build_tools_version

dexOptions {
Expand Down
1 change: 1 addition & 0 deletions ClientLib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- Support devices without Bluetooth since there are other connection types -->
<uses-feature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.droidplanner.services.android.impl.api;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
Expand Down Expand Up @@ -219,18 +223,44 @@ public void onCreate() {
private void updateForegroundNotification() {
final Context context = getApplicationContext();

//Put the service in the foreground
final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
.setContentTitle("DroneKit-Android")
.setPriority(NotificationCompat.PRIORITY_MIN)
.setSmallIcon(R.drawable.ic_stat_notify);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startMyOwnForeground();
}
else {
//Put the service in the foreground
final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
.setContentTitle("DroneKit-Android")
.setPriority(NotificationCompat.PRIORITY_MIN)
.setSmallIcon(R.drawable.ic_stat_notify);

final int connectedCount = droneApiStore.size();
if (connectedCount > 1) {
notifBuilder.setContentText(connectedCount + " connected apps");
}

final int connectedCount = droneApiStore.size();
if (connectedCount > 1) {
notifBuilder.setContentText(connectedCount + " connected apps");
final Notification notification = notifBuilder.build();
startForeground(FOREGROUND_ID, notification);
}
}

final Notification notification = notifBuilder.build();
@TargetApi(Build.VERSION_CODES.O)
private void startMyOwnForeground(){
String NOTIFICATION_CHANNEL_ID = "DroneKit-Android";
String channelName = "DroidPlanner Service";
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
//chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert manager != null;
manager.createNotificationChannel(chan);

Notification.Builder notificationBuilder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.drawable.ic_stat_notify)
.setContentTitle("DroneKit-Android")
.setPriority(Notification.PRIORITY_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.build();
startForeground(FOREGROUND_ID, notification);
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
ext {
play_services_version = '8.4.0'

android_build_sdk_version = 23
android_build_sdk_version = 28
android_build_tools_version = '23.0.2'
android_build_target_sdk_version = 22
android_build_min_sdk_version = 14
Expand Down

0 comments on commit 01d3448

Please sign in to comment.