Skip to content Skip to sidebar Skip to footer

Open An Activity To Edit Contact In Sync Adapter

In the Android SampleSyncAdapter there is the following piece of code: /** * Adds a profile action * * @param userId the userId of the sample SyncAdapter user object * @return

Solution 1:

I think your intent filter might be incorrect. According to this entry, the correct action and data items should be something like the following:

<intent-filter><actionandroid:name="android.intent.action.VIEW" /><categoryandroid:name="android.intent.category.DEFAULT" /><dataandroid:mimeType="vnd.android.cursor.item/vnd.myapp.profile" /></intent-filter>

Solution 2:

This is what I did. In the manifest file I added these intent filters for one of my activity

<intent-filter ><actionandroid:name="android.intent.action.VIEW" /><categoryandroid:name="android.intent.category.DEFAULT" /><dataandroid:mimeType="vnd.android.cursor.item/vnd.myapp.profile" /></intent-filter><intent-filter ><actionandroid:name="android.intent.action.EDIT" /><categoryandroid:name="android.intent.category.DEFAULT" /><dataandroid:host="contacts"android:mimeType="vnd.android.cursor.item/person" /><dataandroid:host="com.android.contacts"android:mimeType="vnd.android.cursor.item/contact" /><dataandroid:host="com.android.contacts"android:mimeType="vnd.android.cursor.item/raw_contact" /></intent-filter>

The first one will be broadcasted when the user clicks on the profile action that I added in my sync adapter accounts using the code in the sample sync adapter (see above)

The second one allows you to handle the intent that is boradcasted by the native address book when the user wants to edit the contact. Consider that in the first case because the mimetype is that one of your syncadapter your activity will be called directly. In the second case a dialog will be shown with the list of applications registered to handle the android.intent.action.EDIT for android:mimeType="vnd.android.cursor.item/person", android:mimeType="vnd.android.cursor.item/contact" etc

In my activity I have a method like this:

booleanhandleIntent(Intent intent) {
    Stringaction= intent.getAction();

    Uriuri= intent.getData();
    if (action.equalsIgnoreCase(Intent.ACTION_VIEW)) {
        handleProfileAction(uri);  // in this case uri points to ProfileAction Data raw that is one of the Data that your sync adaoter has added in the raw contact 
    } elseif (action.equalsIgnoreCase(Intent.ACTION_EDIT)) {
        editYourContact(uri); // in this case the uri points to the Contact containing you raw contact although at least on SonuEricsson  Xperia mini when this intent is broadcasted by the context menu "edit contact" command I receive the URI of the raw contact when there is only one.
    }
    returntrue;
}

Post a Comment for "Open An Activity To Edit Contact In Sync Adapter"