summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormvglasow <michael -at- vonglasow.com>2019-02-25 22:54:17 +0100
committermvglasow <michael -at- vonglasow.com>2019-02-26 00:44:55 +0100
commitc1bac9a01f731f0008554ef5eb8b1a4a2e3e753d (patch)
tree48b997332db1b53e68484efa1495db5af4bc17cf
parentbb34c13a582e1a6b13f3da7a342fc7eccb081b42 (diff)
downloadnavit-c1bac9a01f731f0008554ef5eb8b1a4a2e3e753d.tar.gz
Fix:port/Android:Create notification channel on API 26+
Signed-off-by: mvglasow <michael -at- vonglasow.com>
-rw-r--r--navit/android/res/values/strings.xml1
-rw-r--r--navit/android/src/org/navitproject/navit/Navit.java29
2 files changed, 29 insertions, 1 deletions
diff --git a/navit/android/res/values/strings.xml b/navit/android/res/values/strings.xml
index ae80265e3..f321991e7 100644
--- a/navit/android/res/values/strings.xml
+++ b/navit/android/res/values/strings.xml
@@ -7,6 +7,7 @@
<string name="cancel">Cancel</string>
<!-- NOTIFICATION -->
+ <string name="channel_name">Navit</string>
<string name="notification_ticker">Navit started</string>
<string name="notification_event_default">Navit running</string>
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java
index 5c2d15a72..488095a4a 100644
--- a/navit/android/src/org/navitproject/navit/Navit.java
+++ b/navit/android/src/org/navitproject/navit/Navit.java
@@ -26,6 +26,7 @@ import android.app.AlertDialog;
import android.app.Application;
import android.app.Dialog;
import android.app.Notification;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@@ -90,6 +91,7 @@ public class Navit extends Activity {
private static final int NavitSelectStorage_id = 43;
private static String NavitLanguage;
private static Resources NavitResources = null;
+ private static final String CHANNEL_ID = "org.navitproject.navit";
private static final String NAVIT_PACKAGE_NAME = "org.navitproject.navit";
private static final String TAG = "Navit";
static String map_filename_path = null;
@@ -118,6 +120,25 @@ public class Navit extends Activity {
}
}
+ private void createNotificationChannel() {
+ /*
+ * Create the NotificationChannel, but only on API 26+ because
+ * the NotificationChannel class is new and not in the support library
+ */
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ CharSequence name = getString(R.string.channel_name);
+ //String description = getString(R.string.channel_description);
+ int importance = NotificationManager.IMPORTANCE_LOW;
+ NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
+ //channel.setDescription(description);
+ /*
+ * Register the channel with the system; you can't change the importance
+ * or other notification behaviors after this
+ */
+ NotificationManager notificationManager = getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(channel);
+ }
+ }
public void removeFileIfExists(String source) {
File file = new File(source);
@@ -343,10 +364,16 @@ public class Navit extends Activity {
// NOTIFICATION
// Setup the status bar notification
// This notification is removed in the exit() function
+ if (isLaunch)
+ createNotificationChannel();
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Grab a handle to the NotificationManager
PendingIntent appIntent = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
+ Notification.Builder builder;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ builder = new Notification.Builder(getApplicationContext(), CHANNEL_ID);
+ else
+ builder = new Notification.Builder(getApplicationContext());
builder.setContentIntent(appIntent);
builder.setAutoCancel(false).setOngoing(true);
builder.setContentTitle(getTstring(R.string.app_name));