2013-05-10 106 views
0

我已經創建了一個用於在android中創建新聯繫人的備用應用。當我們創建聯繫人時它工作正常。創建聯繫人時從通話記錄中獲取號碼

但是,當我們從通話記錄中創建聯繫人並在上下文菜單中選擇「創建聯繫人」時,我無法獲取用於創建聯繫人的電話號碼。

Plz幫我...

+0

您使用ACTION_INSERT意圖過濾器? – stinepike 2013-05-10 15:24:26

+0

是的。我正在使用ACTION_INSERT意圖過濾器。 – user2370472 2013-05-11 09:50:28

回答

0

它可能有點晚,但這對我很有用。

在你的Android manif `

  <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter android:label="Edit/Add Property/Requirement"> 
       <action android:name="android.intent.action.EDIT" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
       <data android:mimeType="vnd.android.cursor.item/person" android:host="contacts" /> 
       <data android:mimeType="vnd.android.cursor.item/contact" android:host="com.android.contacts" /> 
       <data android:mimeType="vnd.android.cursor.item/raw_contact" android:host="com.android.contacts" /> 
      </intent-filter> 
     <intent-filter android:label="Add Property/Requirement"> 
      <action android:name="android.intent.action.INSERT" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="vnd.android.cursor.dir/person" /> 
      <data android:mimeType="vnd.android.cursor.dir/contact" /> 
      <data android:mimeType="vnd.android.cursor.dir/raw_contact" /> 
     </intent-filter> 
    </activity>` 

添加這此活動將是一個建立聯繫。而活動中,使用此代碼來獲取電話號碼

Intent intent = getIntent(); 
    try{ 
     Uri uri = intent.getData(); 
     if (uri.toString().endsWith("contacts")) // new contact 
     { 
      phoneNumber = intent 
        .getStringExtra(ContactsContract.Intents.Insert.PHONE); 
     } 
     else{ 
      ContactID = ""+ContentUris.parseId(uri); 
      phoneNumber = intent 
        .getStringExtra(ContactsContract.Intents.Insert.PHONE); 
     } 
    } 
    catch(Exception E){ 

    } 

希望這有助於:)

相關問題