googlecodelabs/background-location-updates-android-o

Google Code Labs: Background Location Updates in Android "O" ClassNotFoundException

Opened this issue · 2 comments

The Background Location Updates in Android "O" code lab has a minSdkVersion of 16 but the source code uses a number of API features that are, for example, only available in SDK 24 and 26. This results in the application halting with ClassNotFoundException when run on any device < SDK 26.
The solution is to set minSdkVersion to 26.

LocationResultHelper(Context context, List<Location> locations) {
    mContext = context;
    mLocations = locations;

                                                                       API 26
    NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL,
                                                                                                    API 24
            context.getString(R.string.default_channel), NotificationManager.IMPORTANCE_DEFAULT);
                           API 26        
    channel.setLightColor(Color.GREEN);
                           API 26
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
                                                             API 26
    getNotificationManager().createNotificationChannel(channel);
}

I recommend checking the API level, and making notification based on this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { display notification for API 26 } else { display notification for API < 26 }

you can just change "O" with 28 .That will work for you.