如何从通话记录中选择联系人?
这是我的代码,但当我尝试Intent.ACTION_PICK
时,它不起作用
Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
context.startActivity(showCallLog);
最佳答案
我不确定是否可以用action_pick完成,如果可行,您可以为此创建一个pick对话框,例如:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnPick = (Button) findViewById(R.id.btnPick);
btnPick.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String[] strFields = { android.provider.CallLog.Calls._ID,
android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.CACHED_NAME, };
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
final Cursor cursorCall = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, strFields,
null, null, strOrder);
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle("Select recent contact");
android.content.DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface,
int item) {
cursorCall.moveToPosition(item);
Toast.makeText(
MainActivity.this,
cursorCall.getString(cursorCall
.getColumnIndex(android.provider.CallLog.Calls.NUMBER)),
Toast.LENGTH_LONG).show();
cursorCall.close();
return;
}
};
builder.setCursor(cursorCall, listener,
android.provider.CallLog.Calls.CACHED_NAME);
builder.create().show();
}
});
}
}