Android contacts use ContactsSource for lower api levels and ContactsAccountType as default in contacts.xml

StackOverflow https://stackoverflow.com/questions/23405377

I have been experiencing a small problem with the contacts application for android 2.1 where my app causes the contacts application to crush when displaying contacts due to the contacts xml definition.

<ContactsAccountType
    xmlns:android="http://schemas.android.com/apk/res/android"
    viewContactNotifyService=".ContactViewedService">
   ...
</ContactsAccountType>

The error that was being displayed was :

05-01 12:43:31.960: E/AndroidRuntime(1064): FATAL EXCEPTION: main
05-01 12:43:31.960: E/AndroidRuntime(1064): java.lang.IllegalStateException: Top level element must be ContactsSource
05-01 12:43:31.960: E/AndroidRuntime(1064):     at com.android.contacts.model.ExternalSource.inflate(ExternalSource.java:133)
05-01 12:43:31.960: E/AndroidRuntime(1064):     at com.android.contacts.model.ExternalSource.inflate(ExternalSource.java:104)
05-01 12:43:31.960: E/AndroidRuntime(1064):     at com.android.contacts.model.ContactsSource.ensureInflated(ContactsSource.java:98)
05-01 12:43:31.960: E/AndroidRuntime(1064):     at com.android.contacts.model.Sources.getInflatedSource(Sources.java:311)

I managed to trace and found that I needed to switch ContactsAccountType to ContactsSource in the contacts.xml file which is deprecated so my question is:

Is there a way I can have contactsSource for lower api versions as a fallback and ContactsAccountType as the default in my xml description?

有帮助吗?

解决方案

Of course you can.

You can define old xml with ContactsSource in default xml folder

And create second xml with ContactsAccountType in xml-v11 folder.

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top