2011-03-30 26 views
6

我爲我的聯繫人添加了自定義字段。它包括:使用聯繫人的自定義字段執行某些操作

<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" /> 

現在。當用戶在Android Contacs中選擇此字段時,我想執行一些操作(例如 - 啓動一項活動)。我如何實現這一點? (它會類似於Facebook的自定義字段 - 顯示個人資料頁面)

+0

請問您如何添加自定義字段並從該自定義字段中導航到您的應用程序單擊 – MohanRaj 2016-06-21 02:53:54

+0

@MohanRaj,我已在多年前使用此功能......首先, - 我忘記了這一點項目和第二個 - 我相信,自那時以來很多API被更改 – 2016-06-21 13:59:17

回答

11

我找到了答案。我們可以通過以下方式實現此功能: 1)創建新類型的聯繫人字段(請參閱答案末尾的鏈接);

2)創建活動,將執行此操作:添加特殊意圖的活動在我們的Manifest.xml

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):

<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> 

答案(及全教程)被發現here

+0

可愛的人:)謝謝 – Umer 2015-08-09 11:07:46