Mr_vmh
Mr_vmh

Reputation: 167

Put our calling- or SMS-app in the "Connected Apps" list contact app

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.

enter image description here

Upvotes: 0

Views: 171

Answers (1)

dev.tejasb
dev.tejasb

Reputation: 578

Looking into Telegram Android code on GitHub, I've collected following codes which will help you achieve what you are trying to:

  1. AndroidManifest.xml
<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

  1. auth.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.

  1. auth_menu.xml
<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 this.

  1. sync_contacts.xml
<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.

  1. contacts.xml
<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

this

  1. Last but not least, you need to add your code for AuthenticatorService and ContactsSyncAdapterService. For this, refer the source code I mentioned at start.

Upvotes: 0

Related Questions