Reputation: 167
I need our app to be shown as an option in the "Connected Apps" list of the android's default contact app, just like how WhatsApp, Truecaller and Telegram etc. - as shown in the image below.
I've tried with ContentProvider
and SyncAdapter
but without luck.
Upvotes: 0
Views: 171
Reputation: 578
Looking into Telegram Android code on GitHub, I've collected following codes which will help you achieve what you are trying to:
<service android:name=".AuthenticatorService" android:exported="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/auth"/>
</service>
<service android:name=".ContactsSyncAdapterService" android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/sync_contacts" />
<meta-data android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts" />
</service>
You need to add these two services in your AndroidManifest.xml
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="org.telegram.messenger"
android:icon="@drawable/ic_launcher_dr"
android:smallIcon="@drawable/ic_launcher_dr"
android:label="@string/AppName"
android:accountPreferences="@xml/auth_menu"/>
Change parameters as per your app needs like icon, etc.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/Settings"/>
<PreferenceScreen android:key="account_settings"
android:title="@string/AccountSettings"
android:summary="">
<intent android:action="org.telegram.messenger.OPEN_ACCOUNT"
android:targetPackage="org.telegram.messenger"
android:targetClass="org.telegram.ui.LaunchActivity"/>
</PreferenceScreen>
</PreferenceScreen>
This will be visible in the phone settings under Accounts like .
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="com.android.contacts"
android:accountType="org.telegram.messenger"/>
Modify this as per your app needs.
<ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android">
<ContactsDataKind android:icon="@drawable/ic_launcher_dr"
android:mimeType="vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile"
android:summaryColumn="data2"
android:detailColumn="data3"
android:detailSocialSummary="true"/>
<ContactsDataKind android:icon="@drawable/ic_launcher_dr"
android:mimeType="vnd.android.cursor.item/vnd.org.telegram.messenger.android.call"
android:summaryColumn="data2"
android:detailColumn="data3"
android:detailSocialSummary="true"/>
<ContactsDataKind android:icon="@drawable/ic_launcher_dr"
android:mimeType="vnd.android.cursor.item/vnd.org.telegram.messenger.android.call.video"
android:summaryColumn="data2"
android:detailColumn="data3"
android:detailSocialSummary="true"/>
</ContactsAccountType>
These are the shortcuts shown under your apps name like
AuthenticatorService
and ContactsSyncAdapterService. For this, refer the source code I mentioned at start.Upvotes: 0