0

デバイスのデフォルトのテキスト メッセージング アプリケーションに現在保存されているテキスト メッセージ (SMS) の会話を持つ連絡先の連絡先情報 (名前と番号) を取得できるようにしたいと考えています。これを行う最善の方法は何ですか?

4

1 に答える 1

1

以下の URI を照会して、sms および mms でアドレス指定されているすべてのアドレスを取得することをお勧めします。

content://mms-sms/conversations

address列 を取得する必要があります

ContentResolver contentResolver = getContentResolver(); 
    final String[] projection = new String[]{"*"}; 
    Uri uri = Uri.parse("content://mms-sms/conversations/"); 
    Cursor query = contentResolver.query(uri, projection, null, null, null);
    String phone = "";
    while(query.moveToNext()){
    phone = query.getString(query.getColumnIndex("address"));
    Log.d("test",phone);
    }

編集: hereからコピーされた以下の関数を確認できます。上記の住所列から選択した番号をこの関数に渡します

private String getContactNameFromNumber(String number) {
    // define the columns I want the query to return
    String[] projection = new String[] {
            Contacts.Phones.DISPLAY_NAME,
            Contacts.Phones.NUMBER };

    // encode the phone number and build the filter URI
    Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(number));

    // query time
    Cursor c = getContentResolver().query(contactUri, projection, null,
            null, null);

    // if the query returns 1 or more results
    // return the first result
    if (c.moveToFirst()) {
        String name = c.getString(c
                .getColumnIndex(Contacts.Phones.DISPLAY_NAME));
        c.close();
        return name;
    }
    c.close();
    // return the original number if no match was found
    return number;
}

すべての番号に対してこれを呼び出すと遅くなるため、クエリに一致するようにこれを編集する必要があります。

于 2012-08-16T17:40:38.767 に答える