googlecodelabs / background-location-updates-android-o

Sample for background location changes in Android "O"
Other
81 stars 57 forks source link

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

Open MonteCreasor opened 7 years ago

MonteCreasor commented 7 years ago

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);
}
deyanm commented 6 years ago

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 }

BlackBlind567 commented 5 years ago

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