1. Download our Official Android App: Forums for Android!

Apps Custom account type

Discussion in 'Android Development' started by sipme, Jan 15, 2013.

  1. sipme

    sipme Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Jan 15, 2013

    Jan 15, 2013
    2
    0
    25
    Hello to all
    I am using custom account type for my application.
    The accounts are created and shown correctly under all version of androids.
    However i have some problem with contacts added to this accounts.

    1) Under android 2.3 in contact groups account is shown as 55XXXX instead of 055XXXXX ( begining 0 is removed from name ).
    when entering some group icon that is shown is the green person icon ( as for phone ) instead of custom icon.
    When i view Joined contacts i see same icon and account type appears as Unknown instead of my account type.

    2) Under android 4.x the account does not shows up under groups and the contact group added by application appears under general groups list.
    Also custom fields added to contact are not shown at all.However icons and account type are shown correctly.


    the application manifest part for defining authenticator and sync adapter :
    [HIGH]<service android:name="mobi.sipme.android.auth.SipmeAuthenticationService"
    android:exported="true" >
    <intent-filter>
    <action android:name="android.accounts.AccountAuthenticator" >
    </action>
    </intent-filter>

    <meta-data
    android:name="android.accounts.AccountAuthenticator"
    android:resource="@xml/authenticator" >
    </meta-data>
    </service>

    <service
    android:name="mobi.sipme.android.auth.SipmeSyncService"
    android:exported="true">
    <intent-filter>
    <action
    android:name="android.content.SyncAdapter" />
    </intent-filter>
    <meta-data
    android:name="android.content.SyncAdapter"
    android:resource="@xml/syncadapter" />
    <meta-data
    android:name="android.provider.CONTACTS_STRUCTURE"
    android:resource="@xml/contacts" />
    </service>[/HIGH]

    authenticator xml :
    [HIGH]<?xml version="1.0" encoding="utf-8"?>
    <account-authenticator xmlns:android="ANDROID_SCHEMA"
    android:accountType="mobi.sipme"
    android:icon="@drawable/sipme"
    android:label="@string/app_name"
    android:smallIcon="@drawable/sipme"
    />[/HIGH]

    sync adapter xml :
    [HIGH]<?xml version="1.0" encoding="utf-8"?>
    <sync-adapter xmlns:android="ANDROID_SCHEMA"
    android:contentAuthority="com.android.contacts"
    android:accountType="mobi.sipme"
    android:supportsUploading="false"
    android:userVisible="true"
    android:isAlwaysSyncable="true"
    />[/HIGH]

    contacts xml :
    [HIGH]<?xml version="1.0" encoding="utf-8"?>
    <ContactsSource
    xmlns:android="ANDROID_SCHEMA"
    >
    <ContactsDataKind
    android:mimeType="vnd.android.cursor.item/vnd.sipme.mobi.im"
    android:icon="@drawable/sipme"
    android:summaryColumn="data2"
    android:detailColumn="data3"
    android:detailSocialSummary="true" />

    <ContactsDataKind
    android:mimeType="vnd.android.cursor.item/vnd.sipme.mobi.audio"
    android:icon="@drawable/sipme"
    android:summaryColumn="data2"
    android:detailColumn="data3"
    android:detailSocialSummary="false" />

    <ContactsDataKind
    android:mimeType="vnd.android.cursor.item/vnd.sipme.mobi.video"
    android:icon="@drawable/sipme"
    android:summaryColumn="data2"
    android:detailColumn="data3"
    android:detailSocialSummary="true" />

    </ContactsSource>[/HIGH]


    code for adding account and group for it :
    [HIGH]Account account = new Account(accountName, SipmeAccountAuthenticator.ACCOUNT_TYPE);
    Bundle userData=new Bundle();
    userData.putString("primary", "0");
    if(masterAccount!=null)
    accountManager.setUserData(account, "master", masterAccount);

    accountManager.addAccountExplicitly(account,password, userData);

    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.Groups.CONTENT_URI);
    builder.withValue(ContactsContract.Groups.ACCOUNT_NAME, account.name);
    builder.withValue(ContactsContract.Groups.ACCOUNT_TYPE, SipmeAccountAuthenticator.ACCOUNT_TYPE);
    builder.withValue(ContactsContract.Groups.TITLE, "All contacts");
    builder.withValue(ContactsContract.Groups.GROUP_VISIBLE,1);
    operationList.add(builder.build());

    try
    {
    accountManager.setUserData(account, "default_group", String.valueOf(ContentUris.parseId(context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList)[0].uri)));
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }

    ContentResolver.setSyncAutomatically(account,ContactsContract.AUTHORITY, true);
    ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY_URI);
    ContentValues cv = new ContentValues();
    cv.put(Groups.ACCOUNT_NAME, account.name);
    cv.put(Groups.ACCOUNT_TYPE, account.type);
    cv.put(Settings.UNGROUPED_VISIBLE, true);
    try
    {
    client.insert(Settings.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(), cv);
    }
    catch (RemoteException e)
    {

    }[/HIGH]

    Any help will be greatly appreciated
    Thanks and best regards
     

    Advertisement

Share This Page

Loading...