如何向我的 SyncAdapter 添加类别
我已经尝试过很棒的 Google 示例来从网络服务同步联系人,效果很好。 这称为 SampleSyncAdapter,确实值得:http://developer.android。 com/resources/samples/SampleSyncAdapter/index.html
我成功了一切,但我在示例中和文档中都找不到添加链接到自定义活动的类别的方法,就像下面的屏幕截图一样:
(我只有带有复选框的同步帐户选项)
所以,我的问题是:如何添加帐户设置类别?
I have tried the great Google example to sync contact from a webservice and that work fine.
This is called the SampleSyncAdapter and really worth it: http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
I succed everything, but I cannot found in the example nor in the documentation a way to add a category that would link to a custom activity, exactly like the screenshot below:
(I have only the sync account option with the checkbox)
So, my question is: how can I add the account settings category?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
herschel 的回答提供了链接到通用解决方案。以下是如何将 SampleSyncAdapter 源修改为添加自定义首选项 (Android 2.3.4),如上面的屏幕截图所示:
请记住,帐户管理器是作为系统进程运行的,因此如果您的帐户中存在未处理的异常,手机将会崩溃代码、清单条目丢失或 xml 中存在错误。
创建
account_preferences.xml
资源文件。android:key
值必须指定为“account_settings”
。定义时关闭
PreferenceCategory
标记;如果您将PreferenceScreen
放入类别中,则当您单击首选项时手机将会崩溃。XML:
在
authenticator.xml
末尾添加对account_preferences.xml
的引用:创建首选项活动并将其添加到清单中。我使用了 我们如何控制 Android 同步适配器首选项?。
a. 将活动添加到清单:
b.这是最简单的
AccountPreferences.java
:c.这是带有硬编码字符串的
preferences_resources.xml
:就是这样。安装您的代码,打开帐户,然后选择您的 SampleSyncAdapter 帐户 (user1)。选择帐户设置,您会看到设置活动。
herschel's answer provides a link to a generic solution. Here's how to modify the SampleSyncAdapter source to add custom preferences (Android 2.3.4) that look like the screenshot above:
Remember that the account manager is running as a system process, so the phone will crash if there's an unhandled exception in your code, a missing manifest entry, or an error in your xml.
Create an
account_preferences.xml
resource file.android:key
value must be specified as"account_settings"
.close the
PreferenceCategory
tag when you define it; if you put thePreferenceScreen
inside the category the phone will crash when you click on the preference.XML:
Add a reference to
account_preferences.xml
at the end ofauthenticator.xml
:Create a preference activity and add it to the manifest. I used a simplified version of the sample code from the answer to How do we control an Android sync adapter preference?.
a. Add the activity to the manifest:
b. Here's the most trivial
AccountPreferences.java
:c. Here's
preferences_resources.xml
with hard-coded strings:That's it. Install your code, open the accounts, and select your SampleSyncAdapter account (user1). Select Account Settings and you see the settings activity.