将 Contacts 和 ContactsContract 合并到 Android 应用程序中
大家好,
我意识到这个问题以前已经以其他形式提出过,相信我,我已经在网上搜索了好几天试图找到答案。然而,我对 Android 和 Java 还很陌生,我需要一些指导。
我目前有两个版本的应用程序,一个适用于 Android 1.5 和 1.6,另一个适用于 2.0 及更高版本。您可能已经猜到了,这是因为 Contacts API 不同。
我最近意识到可以通过使用动态可加载类将这两种方法组合到一个应用程序中。非常酷!经过几天的尝试,我仍然没能成功......或者至少,它不会运行。
我遇到过 3 个如何做到这一点的例子 - 一个由 Google 提供,称为“名片”,另一个与 Spinners 有关,第三个是这里某人创建的。我的问题是,在我看来,每一个都有一个令人惊叹的东西。
我在 Windows 7 上使用 Eclipse。我的应用程序首先是为 A1.5 创建的,所以这就是我要升级的应用程序。发生的情况是我的 ContactsAccessorNewApi 类需要导入 ContactContracts,根据 Eclipse,这是行不通的,因为我的项目最初是在不支持它的情况下构建的。因此,它不会运行。我尝试将 SDK level 5 的 android.jar 添加到项目中,但这会造成一团糟的其他问题。
我的应用程序的这部分代码与 Google 示例“名片”完全相同 - 因此,如果有人可以帮助我跨越这个障碍,我将非常感激。我很乐意发布您回答我的问题所需的任何代码。
谢谢你!
Greetings all,
I realize this issue has been posed before in other forms, and believe me, I have been searching the net for days trying to find the answer. However, I'm fairly new to Android and Java, and I need a little guidance please.
I presently have two version of my app, one for Android 1.5 and 1.6, and another for 2.0 and beyond. As you probably guessed, it's because the Contacts API is different.
I recently became aware that it was possible to combine both methods into a single app, by using dynamically loadable classes. Very cool! After days of attempts, I still haven't been able to do it successfully... or at least, it won't run.
I have come across 3 examples of how to do this - one by Google, called "Business Card", another that had something to do with Spinners, and a 3rd was something someone here created. My problem is that each one seems to me to have a showstopper.
I'm using Eclipse on Windows 7. My app was first created for A1.5, so that's the one I'm upgrading. What's happening is that my ContactsAccessorNewApi class needs to import the ContactContracts, and according to Eclipse, that won't work because my project was originally built without support for it. Hence, it won't run. I've tried adding the android.jar for SDK level 5 into the project, but that creates a whole mess of other problems.
My code for this pat of my app is exactly like the Google example "Business Card" - so if someone could help me cross this hurdle, I'd be very grateful. I'll be happy to post any code that you need to answer my question.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您是指这个示例项目,那是我的。
您需要将构建目标(项目属性 > Android)设置得足够高,以便
ContactsContract
存在(android-5
或更高版本)。只要清单中的
android:minSdkVersion
设置为支持早期版本的 Android(例如,Android 1.5 为 3),您的应用仍将安装在较旧的模拟器 AVD 和设备上。是的,不要这样做。
If you mean this sample project, that's mine.
You need to set your build target (Project Properties > Android) to be high enough that
ContactsContract
exists (android-5
or higher).So long as your
android:minSdkVersion
in your manifest is set to support earlier versions of Android (e.g., 3 for Android 1.5), your app will still install on older emulator AVDs and devices.Yeah, don't do that.