Livecard Backward Compatibility

Google Glass Orange Shades

If you haven’t found out by now, the update to the Android SDK removed the TimelineManager class from the GDK and it removed the method for retrieving a LiveCard as well. This means that all existing LiveCard code MUST be updated to run on both XE12 and XE16.

Here is a way to acquire a LiveCard on both XE12 and XE16.


public static LiveCard getLiveCard(Context context, String tag) {
try {
Class tmClass = Class.forName("com.google.android.glass.timeline.TimelineManager");
Method from = tmClass.getMethod("from", new Class[] { Context.class });
Object tm = from.invoke(tmClass, context);
Method createLiveCard = tmClass.getMethod("createLiveCard", new Class[] { String.class });
return (LiveCard) createLiveCard.invoke(tm, tag);
} catch (Exception e) {
// TimelineManager must be gone
return new LiveCard(context, tag);
}
}

Everyone’s device should be updated by now, but you can use the above method to make sure things are working on XE 12 and XE16. To use this code, you just need to replace your existing call method with the one above.