通过检测 1.6 目标应用程序是否为 2.1 设备来显示动态壁纸?

发布于 2024-08-27 16:15:15 字数 283 浏览 5 评论 0原文

我们正在使用目标 SDK 1.6 构建 Android 应用程序,因此它将在 1.6 及更高版本的设备上运行。我们希望支持动态壁纸,我们知道动态壁纸仅限 2.1+。有没有一种方法可以构建一个以 1.6 SDK 作为目标的应用程序,但检测它运行的设备是否是 2.1,并且仅在这种情况下调用动态壁纸 API。

我们试图避免构建单独的 1.6 和 2.1 版本,并且希望能够仅支持 2.1 设备的动态壁纸。所以要明确的是 - 1 个应用程序,可以支持 1.6 及更高版本,并支持 2.1 设备的动态壁纸。

有办法做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2024-09-03 16:15:15

或许。我没有使用过动态壁纸,但以下是我在 2.* 上使用 AccountManager 的方法,但在 1.* 上有一个后备方案,因为它不可用。

我使用 2.1 SDK 构建,但我的清单声明

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

这确实允许应用程序在 1.5 及以上版本的设备上运行。

我将 android.accounts.AccountManager 的使用限制为包装类,我将其称为 UserEmailFetcher。

可以在 2.* 设备上使用此类。然而,在早期的设备上,当代码中第一次遇到此类时,将触发 java.lang.VerifyError。我抓住了这一点,并执行了一些后备操作。

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

希望有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文