获取选择联系人方法采用ToolPhone
This commit is contained in:
parent
f156e99769
commit
721e8616bc
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
@ -14,7 +13,7 @@ import android.widget.EditText;
|
|||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.base.BaseActivity;
|
||||
import com.zftlive.android.tools.ToolAlert;
|
||||
import com.zftlive.android.tools.ToolSMS;
|
||||
import com.zftlive.android.tools.ToolPhone;
|
||||
import com.zftlive.android.tools.ToolString;
|
||||
|
||||
public class SMSOperationActivity extends BaseActivity implements
|
||||
|
@ -74,9 +73,7 @@ public class SMSOperationActivity extends BaseActivity implements
|
|||
switch (v.getId()) {
|
||||
case R.id.btn_choice:
|
||||
// 跳转至选择联系人界面
|
||||
Intent intent = new Intent(Intent.ACTION_PICK,
|
||||
ContactsContract.Contacts.CONTENT_URI);
|
||||
this.startActivityForResult(intent, CHOICE_PHONE);
|
||||
ToolPhone.toChooseContactsList(this, CHOICE_PHONE);
|
||||
break;
|
||||
case R.id.btn_bind:
|
||||
if (ToolString.isNoBlankAndNoNull(phoneNumber)) {
|
||||
|
@ -94,7 +91,7 @@ public class SMSOperationActivity extends BaseActivity implements
|
|||
|
||||
if (ToolString.isNoBlankAndNoNull(phoneNumber)
|
||||
&& ToolString.isNoBlankAndNoNull(strContent)) {
|
||||
ToolSMS.sendMessage(phoneNumber, strContent);
|
||||
ToolPhone.sendMessage(this,phoneNumber, strContent);
|
||||
// ToolSMS.sendMessage(this, phoneNumber,
|
||||
// strContent);//跳转到发送短信界面
|
||||
} else {
|
||||
|
@ -115,7 +112,7 @@ public class SMSOperationActivity extends BaseActivity implements
|
|||
Uri uri = data.getData();
|
||||
Cursor c = managedQuery(uri, null, null, null, null);
|
||||
c.moveToFirst();
|
||||
et_phonenumber.setText(getContactPhone(c));
|
||||
et_phonenumber.setText(ToolPhone.getChoosedPhoneNumber(this,resultCode,data));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -123,47 +120,4 @@ public class SMSOperationActivity extends BaseActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
// 获取联系人电话
|
||||
private String getContactPhone(Cursor cursor) {
|
||||
|
||||
int phoneColumn = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
|
||||
int phoneNum = cursor.getInt(phoneColumn);
|
||||
String phoneResult = "";
|
||||
// System.out.print(phoneNum);
|
||||
if (phoneNum > 0) {
|
||||
// 获得联系人的ID号
|
||||
int idColumn = cursor.getColumnIndex(ContactsContract.Contacts._ID);
|
||||
String contactId = cursor.getString(idColumn);
|
||||
// 获得联系人的电话号码的cursor;
|
||||
Cursor phones = getContentResolver().query(
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||
null,
|
||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
|
||||
+ contactId, null, null);
|
||||
// int phoneCount = phones.getCount();
|
||||
// allPhoneNum = new ArrayList<String>(phoneCount);
|
||||
if (phones.moveToFirst()) {
|
||||
// 遍历所有的电话号码
|
||||
for (; !phones.isAfterLast(); phones.moveToNext()) {
|
||||
int index = phones
|
||||
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
||||
int typeindex = phones
|
||||
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
|
||||
int phone_type = phones.getInt(typeindex);
|
||||
String phoneNumber = phones.getString(index);
|
||||
switch (phone_type) {
|
||||
case 2:
|
||||
phoneResult = phoneNumber;
|
||||
break;
|
||||
}
|
||||
// allPhoneNum.add(phoneNumber);
|
||||
}
|
||||
if (!phones.isClosed()) {
|
||||
phones.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return phoneResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue