Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use application Context for CustomNavigationNotification example #1182

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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