2013-08-02 36 views
0

Om按鈕點擊,我顯示聯繫人選擇框。我從哪裏選擇任何聯繫人。然後顯示聯繫人的電話號碼。如何避免Facebook,watsapp聯繫人ContactsContract.CommonDataKinds

但問題是,有時我沒有看到選擇聯繫人後的電話號碼。我不知道原因,但我想這是因爲選擇器正在顯示Facebook,watsapp聯繫人。

如何過濾僅在選擇器中顯示的手機和SIM卡聯繫人?

我創建像選配:

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
     intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); 
     startActivityForResult(intent, 1); 

搬運及展示,如號碼:

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
if (data != null) { 
Uri uri = data.getData(); 
if (uri != null) { 
Cursor c = null; 
try { 
c = getContentResolver().query(uri, new String[]{ 
ContactsContract.CommonDataKinds.Phone.NUMBER, 
ContactsContract.CommonDataKinds.Phone.TYPE }, 
null, null, null); 

if (c != null && c.moveToFirst()) { 
String number = c.getString(0); 
int type = c.getInt(1); 
showSelectedNumber(type, number); 
} 
} finally { 
if (c != null) { 
c.close(); 
} 
} 
} 
} 
} 

public void showSelectedNumber(int type, String number) { 
    Toast.makeText(this, type + ": " + number, Toast.LENGTH_LONG).show();  
} 

誰能幫助我在這裏。所以無論何時我選擇一個聯繫人,它都必須顯示號碼? 高級謝謝

回答

0

這是我在我的應用程序中使用。

Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 

    if (Build.VERSION.SDK_INT <= 4) { 
     intent.setType(Contacts.People.CONTENT_ITEM_TYPE); 
    } else { 
     intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); 
    } 
+0

已棄用。 –