From 522fd29b4422b67767796eff1beec88355a2584a Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 10 Apr 2012 19:25:22 -0700 Subject: [PATCH] fix to show/return individual phone numbers. Still todo: warn rather than drop numbers not flagged as mobile. --- .../android/xw4/SMSInviteActivity.java | 57 ++++++++----------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java index eaf26bf83..b7e6e39d0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java @@ -104,6 +104,7 @@ public class SMSInviteActivity extends InviteActivity implements TextWatcher { { Intent intent = new Intent( Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI ); + intent.setType( Phone.CONTENT_TYPE ); startActivityForResult( intent, GET_CONTACT ); } @@ -159,43 +160,35 @@ public class SMSInviteActivity extends InviteActivity implements TextWatcher { private void addPhoneNumbers( Intent intent ) { Uri data = intent.getData(); - Cursor cursor = managedQuery( data, null, null, null, null ); + Cursor cursor = managedQuery( data, + new String[] { Phone.DISPLAY_NAME, + Phone.NUMBER, + Phone.TYPE }, + null, null, null ); if ( cursor.moveToFirst() ) { + String name = ""; int len_before = m_phoneRecs.size(); - int index = cursor.getColumnIndex(ContactsContract.Contacts._ID ); - if ( 0 <= index ) { - String id = cursor.getString( index ); - ContentResolver resolver = getContentResolver(); - Cursor pc = - resolver.query( Phone.CONTENT_URI, null, - Phone.CONTACT_ID + " = ?", - new String[] { id }, null ); - String name = ""; - while ( pc.moveToNext() ) { - name = - pc.getString( pc.getColumnIndex( Phone.DISPLAY_NAME)); - String number = - pc.getString( pc.getColumnIndex( Phone.NUMBER ) ); - // int type = - // pc.getInt( pc.getColumnIndex( Phone.TYPE ) ); + name = cursor.getString( cursor.getColumnIndex( Phone.DISPLAY_NAME)); + String number = + cursor.getString( cursor.getColumnIndex( Phone.NUMBER ) ); + int type = cursor.getInt( cursor.getColumnIndex( Phone.TYPE ) ); - if ( /*Phone.TYPE_MOBILE == type && */0 < number.length() ) { - m_phoneRecs.add( new PhoneRec( name, number ) ); - } - } - if ( len_before != m_phoneRecs.size() ) { - saveState(); - rebuildList(); - } else { - int resid = null != name && 0 < name.length() - ? R.string.sms_nomobilef - : R.string.sms_nomobile; - String msg = Utils.format( this, resid, name ); - showOKOnlyDialog( msg ); - } + if ( Phone.TYPE_MOBILE == type && 0 < number.length() ) { + m_phoneRecs.add( new PhoneRec( name, number ) ); } + if ( len_before != m_phoneRecs.size() ) { + saveState(); + rebuildList(); + } else { + int resid = null != name && 0 < name.length() + ? R.string.sms_nomobilef + : R.string.sms_nomobile; + String msg = Utils.format( this, resid, name ); + showOKOnlyDialog( msg ); + } + cursor.close(); } - } + } // addPhoneNumbers private void rebuildList() {