Skip to content

Commit 1c0274a

Browse files
authored
Merge pull request #2 from navit-gps/trunk
merge
2 parents 9563675 + 5352c40 commit 1c0274a

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

navit/android/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<string name="cancel">Cancel</string>
88

99
<!-- NOTIFICATION -->
10+
<string name="channel_name">Navit</string>
1011
<string name="notification_ticker">Navit started</string>
1112
<string name="notification_event_default">Navit running</string>
1213

navit/android/src/org/navitproject/navit/Navit.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.app.Application;
2727
import android.app.Dialog;
2828
import android.app.Notification;
29+
import android.app.NotificationChannel;
2930
import android.app.NotificationManager;
3031
import android.app.PendingIntent;
3132
import android.content.Context;
@@ -90,6 +91,7 @@ public class Navit extends Activity {
9091
private static final int NavitSelectStorage_id = 43;
9192
private static String NavitLanguage;
9293
private static Resources NavitResources = null;
94+
private static final String CHANNEL_ID = "org.navitproject.navit";
9395
private static final String NAVIT_PACKAGE_NAME = "org.navitproject.navit";
9496
private static final String TAG = "Navit";
9597
static String map_filename_path = null;
@@ -118,6 +120,25 @@ public void run() {
118120
}
119121
}
120122

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+
}
121142

122143
public void removeFileIfExists(String source) {
123144
File file = new File(source);
@@ -343,16 +364,31 @@ public void onCreate(Bundle savedInstanceState) {
343364
// NOTIFICATION
344365
// Setup the status bar notification
345366
// This notification is removed in the exit() function
367+
if (isLaunch)
368+
createNotificationChannel();
346369
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Grab a handle to the NotificationManager
347370
PendingIntent appIntent = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
348371

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+
}
356392
nm.notify(R.string.app_name, NavitNotification);// Show the notification
357393

358394
if ((ContextCompat.checkSelfPermission(this,

0 commit comments

Comments
 (0)