Showing Live Wallpaper in a 1.6 target app by detecting if it's a 2.1 device?

六月ゝ 毕业季﹏ 提交于 2019-12-07 19:28:25

问题


We're building an Android app with target SDK 1.6, so it will run on 1.6 devices and higher. We'd like to support Live Wallpapers, which we know is 2.1+ only. Is there a way to build one app with 1.6 SDK as the target, but detect if the device it's running on is 2.1, and only in that scenario call the live wallpaper API.

We're trying to avoid having to build a separate 1.6 and 2.1 versions, and would like to be able to support Live Wallpapers for only 2.1 devices. So to be clear- 1 app, that can support 1.6 and higher, and support live wallpapers for 2.1 devices.

Any way of doing this?


回答1:


Maybe. I haven't worked with Live Wallpapers, but here is how I use the AccountManager on 2.* but have a fallback on 1.* where it isn't available.

I build with the 2.1 SDK, but my Manifest states

<uses-sdk android:minSdkVersion="3" />

This does allow the app to run on 1.5 devices upwards.

I restrict my use of android.accounts.AccountManager to a wrapper class, I called it UserEmailFetcher.

It will be possible to use this class on 2.* devices. However on earlier devices a java.lang.VerifyError will fire the first time this class is encountered in the code. This I catch, and perform some fallback action.

String name;
try {
   name = UserEmailFetcher.getEmail(this); 
} catch (VerifyError e) {
   // Happens if the AccountManager is not available (e.g. 1.x)
}

Hope that helps.



来源:https://stackoverflow.com/questions/2567030/showing-live-wallpaper-in-a-1-6-target-app-by-detecting-if-its-a-2-1-device

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