Hi,
I'm creating my first Android application and I'm looking for a few
advices on several subjects. The context is simple: my application
connects itself to several Instant Messaging servers and it creates a
RawContact in the Contact Provider each one for the contacts found on
these servers. At this time, I got everything working, but I'm not
fully satisfied on several points:
First point: AccountManager
I successfully managed to create an simple account authenticator that
create a new account dedicated to my application. There is no real
authentication behind it, it simply create an empty Account if needed,
that's all. Everything works in an emulator v2.2, however, I can't
even bind to my "AuthenticatorService" in an emulator v2.1-update1.
Here is the error I retrieve from the logcat:
DEBUG/AccountManagerService(64): bind attempt failed for Session:
expectLaunch false, connected false, stats (0/0/0), lifetime 0.001,
addAccount, accountType ACCOUNT_UNIFIED_IM_TYPE, requiredFeatures null
Here is the part of the AndroidManifest.xml related to that
Authenticator:
<service
android:name=".service.core.authenticator.AuthenticatorService"
android:exported="true">
<intent-filter>
<action
android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
And here is the content of the file named '/res/xml/
authenticator.xml':
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/
res/android"
android:accountType="@string/account_type"
android:icon="@drawable/unified_im_icon"
android:smallIcon="@drawable/unified_im_icon"
android:label="@string/app_name"
/>
Second point: creating a RawContact
Once my Account is created (or retrieved), I try to add a new
RawContact, but it seems to me that this process is reeeeaaaally slow,
so I'm wondering if I do it the right way and if you have any tips
that would allow my to speed it up. Here is my code:
ContentValues lValues = new ContentValues();
lValues.put(RawContacts.ACCOUNT_TYPE, lAccountType);
lValues.put(RawContacts.ACCOUNT_NAME, lAccountName);
Uri lRawContactUri =
mService.getContentResolver().insert(RawContacts.CONTENT_URI,
lValues);
Uri lDataUri = Uri.withAppendedPath(lRawContactUri,
Data.CONTENT_DIRECTORY);
ContentValues[] lData = new ContentValues[2];
lData[0] = new ContentValues();
lData[0].put(Entity.RAW_CONTACT_ID, lContact.getSystemId());
lData[0].put(Entity.MIMETYPE, Im.CONTENT_ITEM_TYPE);
lData[0].put(Im.PROTOCOL, ProtocolUtils.toSystemProtocol(pProtocol));
lData[0].put(Im.DATA, pHandle);
lData[1] = new ContentValues();
lData[1].put(Entity.RAW_CONTACT_ID, lContact.getSystemId());
lData[1].put(Entity.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
lData[1].put(StructuredName.DISPLAY_NAME, pDisplayName);
mService.getContentResolver().bulkInsert(lDataUri, lData);
(Yeah, I know, and I'm really sorry for the lack of documentation...)
Third point: reading a list of RawContacts
That's the point that I'm not really proud of, not that the process
is slow, but I'm sure there is a away to make it simpler. Here is what
I do:
1 - First, I query the ContactManager in order to retrieve the _ID of
all the RawContacts that matches my Account:
Cursor lCursor = lResolver.query(
RawContacts.CONTENT_URI,
new String[] {RawContacts._ID},
RawContacts.ACCOUNT_NAME + "=? AND " + RawContacts.ACCOUNT_TYPE
+
"=?",
new String[] {lAccountName, lAccountType},
null);
2 - Then, for EACH RawContact I query the ContentManager in order to
retrieve its IM data, and an other query in order to retrieve its
Display Name:
Cursor lRawCursor = lResolver.query(
lRawContactUri,
new String[] {Im.PROTOCOL, Im.DATA},
Data.MIMETYPE + "=?",
new String[] {Im.CONTENT_ITEM_TYPE},
null);
lRawCursor = lResolver.query(
lRawContactUri,
new String[] {StructuredName.DISPLAY_NAME},
Data.MIMETYPE + "=?",
new String[]{StructuredName.CONTENT_ITEM_TYPE},
null);
So here are my main problems, I'm pretty sure that there are some tips
that would allow me to do the same thing more efficiently, I just hope
someone will be here to give me them ;)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en