Search…
Sample Notification
The example below shows how to create a notification that can be passed to SdkConfig.Builder. We use the android.support.v7.app.NotificationCompat class to build a notification suitable for both old and new Android versions.
The notification channel, necessary for Android 8 and above, has the channel importance set to IMPORTANCE_LOW, the minimum recommended by Google for notifications used for running services.
1
private Notification createNotification() {
2
// PendingIntent that will start your application's MainActivity
3
Intent intent = new Intent(context, MainActivity.class);
4
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
5
6
// On Oreo and above, you must create a notification channel
7
String channelId = "channel-id";
8
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
9
NotificationChannel channel = new NotificationChannel(channelId, "Channel name", NotificationManager.IMPORTANCE_LOW);
10
channel.setShowBadge(false);
11
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
12
notificationManager.createNotificationChannel(channel);
13
}
14
15
return new NotificationCompat.Builder(context, channelId)
16
.setContentTitle(context.getString(R.string.app_name) + " is running")
17
.setContentText("Touch to open.")
18
.setContentIntent(pendingIntent)
19
.setShowWhen(false)
20
.setSmallIcon(R.mipmap.ic_launcher)
21
.setPriority(NotificationCompat.PRIORITY_MIN)
22
.build();
23
}
Copied!
You can quickly test the notification appearance by running a fresh SDK install on an Android Oreo device. The notification will appear the first time the SDK starts automatic detections, or when you manually start a trip. More about this here.
Copy link