Skip to content

Commit

Permalink
Use application Context for CustomNavigationNotification example (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder authored Aug 3, 2018
1 parent d4b366f commit 2c09d73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.services.android.navigation.testapp.activity;

import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -90,7 +91,8 @@ protected void onCreate(Bundle savedInstanceState) {
mapView.getMapAsync(this);

// Use a custom notification
CustomNavigationNotification customNavigationNotification = new CustomNavigationNotification(this);
Context applicationContext = getApplicationContext();
CustomNavigationNotification customNavigationNotification = new CustomNavigationNotification(applicationContext);
MapboxNavigationOptions options = MapboxNavigationOptions.builder()
.navigationNotification(customNavigationNotification)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class CustomNavigationNotification implements NavigationNotification {
private NotificationManager notificationManager;
private int numberOfUpdates;

public CustomNavigationNotification(Context context) {
public CustomNavigationNotification(Context applicationContext) {
// Get the notification manager to update your notification
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager = (NotificationManager) applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);

// Store the builder to update later
customNotificationBuilder = new NotificationCompat.Builder(context, NAVIGATION_NOTIFICATION_CHANNEL)
customNotificationBuilder = new NotificationCompat.Builder(applicationContext, NAVIGATION_NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.ic_navigation)
.setContentTitle("Custom Navigation Notification")
.setContentText("Display your own content here!");
Expand Down

0 comments on commit 2c09d73

Please sign in to comment.