background-location-updates-android-o icon indicating copy to clipboard operation
background-location-updates-android-o copied to clipboard

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

Open MonteCreasor opened this issue 7 years ago • 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);
}

MonteCreasor avatar Sep 30 '17 05:09 MonteCreasor

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 }

deyanm avatar Apr 29 '18 18:04 deyanm

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

BlackBlind567 avatar Mar 05 '19 09:03 BlackBlind567