Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform some action with custom field of Contact

I have added custom field for my Contacts. It consists of:

<ContactsSource xmlns:android="http://schemas.android.com/apk/res/android">
 <ContactsDataKind
  android:icon="@drawable/ic_launcher"
  android:mimeType="vnd.android.cursor.item/vnd.com.mob.my_new.profile"
  android:summaryColumn="data2"
  android:detailColumn="data3"
  android:detailSocialSummary="true" />

for now. I want to perform some action (for example - launch an activity) when user selects this my field in Android Contacs. How I can implement this? (It will be similar to facebook custom field - showing profile page)

like image 601
Anton Derevyanko Avatar asked Mar 30 '11 17:03

Anton Derevyanko


1 Answers

I found the answer. We can implement such functionality by: 1) creating new type of Contacts field (see link at the end of answer);

2) creating an Activity, which will perform this action:

if (getIntent().getData() != null) {
        Cursor cursor = managedQuery(getIntent().getData(), null, null, null, null);
        if (cursor.moveToNext()) {
            String username = cursor.getString(cursor.getColumnIndex("DATA1"));
            TextView tv = (TextView) findViewById(R.id.profiletext);
            tv.setText("This is the profile for " + username);
        }
    } else {
        // How did we get here without data?
        finish();
    }

3) adding special intent to Activity in our Manifest.xml:

<activity android:name=".ProfileActivity"
                android:label="Profile">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile" />
        </intent-filter>
    </activity>

The answer (and full tutorial) was found here.

like image 176
Anton Derevyanko Avatar answered Nov 15 '22 15:11

Anton Derevyanko