Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 +223,47 @@ 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.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);
}


@Override
public void onDestroy() {
super.onDestroy();
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
ext {
play_services_version = '8.4.0'

android_build_sdk_version = 23
android_build_tools_version = '23.0.3'
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