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