|
26 | 26 | import android.app.Application;
|
27 | 27 | import android.app.Dialog;
|
28 | 28 | import android.app.Notification;
|
| 29 | +import android.app.NotificationChannel; |
29 | 30 | import android.app.NotificationManager;
|
30 | 31 | import android.app.PendingIntent;
|
31 | 32 | import android.content.Context;
|
@@ -90,6 +91,7 @@ public class Navit extends Activity {
|
90 | 91 | private static final int NavitSelectStorage_id = 43;
|
91 | 92 | private static String NavitLanguage;
|
92 | 93 | private static Resources NavitResources = null;
|
| 94 | + private static final String CHANNEL_ID = "org.navitproject.navit"; |
93 | 95 | private static final String NAVIT_PACKAGE_NAME = "org.navitproject.navit";
|
94 | 96 | private static final String TAG = "Navit";
|
95 | 97 | static String map_filename_path = null;
|
@@ -118,6 +120,25 @@ public void run() {
|
118 | 120 | }
|
119 | 121 | }
|
120 | 122 |
|
| 123 | + private void createNotificationChannel() { |
| 124 | + /* |
| 125 | + * Create the NotificationChannel, but only on API 26+ because |
| 126 | + * the NotificationChannel class is new and not in the support library |
| 127 | + */ |
| 128 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 129 | + CharSequence name = getString(R.string.channel_name); |
| 130 | + //String description = getString(R.string.channel_description); |
| 131 | + int importance = NotificationManager.IMPORTANCE_LOW; |
| 132 | + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); |
| 133 | + //channel.setDescription(description); |
| 134 | + /* |
| 135 | + * Register the channel with the system; you can't change the importance |
| 136 | + * or other notification behaviors after this |
| 137 | + */ |
| 138 | + NotificationManager notificationManager = getSystemService(NotificationManager.class); |
| 139 | + notificationManager.createNotificationChannel(channel); |
| 140 | + } |
| 141 | + } |
121 | 142 |
|
122 | 143 | public void removeFileIfExists(String source) {
|
123 | 144 | File file = new File(source);
|
@@ -343,16 +364,31 @@ public void onCreate(Bundle savedInstanceState) {
|
343 | 364 | // NOTIFICATION
|
344 | 365 | // Setup the status bar notification
|
345 | 366 | // This notification is removed in the exit() function
|
| 367 | + if (isLaunch) |
| 368 | + createNotificationChannel(); |
346 | 369 | nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Grab a handle to the NotificationManager
|
347 | 370 | PendingIntent appIntent = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
|
348 | 371 |
|
349 |
| - NotificationCompat.Builder builder = new NotificationCompat.Builder(this); |
350 |
| - builder.setContentIntent(appIntent); |
351 |
| - builder.setAutoCancel(false).setOngoing(true); |
352 |
| - builder.setContentTitle(getTstring(R.string.app_name)); |
353 |
| - builder.setContentText(getTstring(R.string.notification_event_default)); |
354 |
| - builder.setSmallIcon(R.drawable.ic_notify); |
355 |
| - Notification NavitNotification = builder.build(); |
| 372 | + Notification NavitNotification; |
| 373 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 374 | + Notification.Builder builder; |
| 375 | + builder = new Notification.Builder(getApplicationContext(), CHANNEL_ID); |
| 376 | + builder.setContentIntent(appIntent); |
| 377 | + builder.setAutoCancel(false).setOngoing(true); |
| 378 | + builder.setContentTitle(getTstring(R.string.app_name)); |
| 379 | + builder.setContentText(getTstring(R.string.notification_event_default)); |
| 380 | + builder.setSmallIcon(R.drawable.ic_notify); |
| 381 | + NavitNotification = builder.build(); |
| 382 | + } else { |
| 383 | + NotificationCompat.Builder builder; |
| 384 | + builder = new NotificationCompat.Builder(getApplicationContext()); |
| 385 | + builder.setContentIntent(appIntent); |
| 386 | + builder.setAutoCancel(false).setOngoing(true); |
| 387 | + builder.setContentTitle(getTstring(R.string.app_name)); |
| 388 | + builder.setContentText(getTstring(R.string.notification_event_default)); |
| 389 | + builder.setSmallIcon(R.drawable.ic_notify); |
| 390 | + NavitNotification = builder.build(); |
| 391 | + } |
356 | 392 | nm.notify(R.string.app_name, NavitNotification);// Show the notification
|
357 | 393 |
|
358 | 394 | if ((ContextCompat.checkSelfPermission(this,
|
|
0 commit comments