Mapbox转弯导航 - 自定义通知 - 电池消耗很高

时间:2018-02-14 10:45:48

标签: android mapbox

我正在制定一项要求,在我们的某个应用程序中提供转弯导航。我能够构建应用程序并且运行良好。我已将自定义通知功能添加到自定义导航活动中,通知效果很好但我的设备电池消耗非常高,有时我收到警告此应用程序消耗更多电池消息。

任何人都能在这一点上帮助我。我也需要节省电池利用率。

这是我的代码段。

公共类CustomNavigationNotification实现NavigationNotification {

private static final int CUSTOM_NOTIFICATION_ID = 91234821;

private Notification customNotification;
private NotificationCompat.Builder customNotificationBuilder;
private NotificationManager notificationManager;
private int numberOfUpdates;

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

    // Store the builder to update later
    customNotificationBuilder = new NotificationCompat.Builder(context, NAVIGATION_NOTIFICATION_CHANNEL)
            .setSmallIcon(R.drawable.caramaps_g)
            .setContentTitle("App name")
            .setContentText("Happy journey");

    // Build the notification
    customNotification = customNotificationBuilder.build();
}

@Override
public Notification getNotification() {
    return customNotification;
}

@Override
public int getNotificationId() {
    return CUSTOM_NOTIFICATION_ID;
}

@Override
public void updateNotification(RouteProgress routeProgress) {
    // Update the builder with a new number of updates
    customNotificationBuilder.setContentText("Diatance you traveled : " + routeProgress.distanceTraveled());

    // Notify the notification manager
    notificationManager.notify(CUSTOM_NOTIFICATION_ID, customNotificationBuilder.build());
}
}

这里我将自定义通知传递给我的导航选项构建器。

MapboxNavigationOptions options1 = MapboxNavigationOptions.builder()                              .navigationNotification(mCustomNavigationNotification)
                            .maneuverZoneRadius(70)
                            .build();
NavigationViewOptions options = NavigationViewOptions.builder()
                            .directionsRoute(currentRoute)
                            .directionsLanguage(Locale.getDefault())
                            .navigationOptions(options1)

.awsPoolId(null).shouldSimulateRoute(simulateRoute).build();
如果我走错了路,请建议我。

提前致谢....

0 个答案:

没有答案
相关问题