Google Glass GDK backward compatibility?

心已入冬 提交于 2019-12-01 22:36:34

For now, I'd use reflection...Probably:

private View buildView() {
    try {
        String cardBuilderName = "com.google.android.glass.widget.CardBuilder";
        Class clazz = Class.forName(cardBuilderName);
        CardBuilder cardBuilder = new CardBuilder(this, CardBuilder.Layout.TEXT);
        cardBuilder.setText(R.string.hello_world);
        return cardBuilder.getView();
    } catch (Exception e) {
        //ClassNotFoundException?
        Log.v(TAG, e.toString());
        Card card = new Card(this);
        card.setText(R.string.hello_world);
        return card.getView();
    }        
}

Note: I haven't tested on old XEs because I've flashed the XE 21.

But this is ugly. Hopefully, we have a better way to handle this.

Are you on XE21.0 or XE20.1? If you are on XE20.1, then CardBuilder is not available. You'll need to wait until your device is updated sometime this week as XE21.0 started rolling out this week.

In terms of checking the runtime version of Glass, definitely the setup currently is not great. Generally though even if GDK classes are deprecated, they will largely be available in future releases to not break backwards compatibility. So you are probably better off sticking with the old API, even if it is deprecated, for several more releases.

With that said, besides using reflection, you could check the incremental build version (http://developer.android.com/reference/android/os/Build.VERSION.html#INCREMENTAL). This should have a 1:1 mapping with the XE releases, though its not advertised as to what the incremental version is for each release (you'll have to experiment to find this).

Since Google Glass is still in a "beta" state, we will need to upgrade to the current GDK version whenever a new release is made. New releases have been made almost monthly.

I expect that once Google Glass has been released in it public form, that the "minimum sdk version" may be supported ... but that announcement has not been made by Google yet.

So .. keep a close eye on changes as each version of the GDK is released (and patches correct problems or add features) so you (and the rest of us) can keep our nascent Glassware (or "to bo" Glassware will continue to run).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!