如何从通话记录中选择联系人?

发布于 2024-12-29 03:52:18 字数 273 浏览 4 评论 0原文

如何从通话记录中选择联系人?

这是我的代码,但是当我尝试 Intent.ACTION_PICK 时,它不起作用

Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
context.startActivity(showCallLog); 

How can I pick a contact from call logs?

This is my code, but when i try Intent.ACTION_PICK , it doesn't work

Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
context.startActivity(showCallLog); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

草莓味的萝莉 2025-01-05 03:52:18

我不确定是否可以使用 ACTION_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();
            }
        });
    }
}

I'm not sure whether it can be done with ACTION_PICK, if it is feasible, you can create simply a pick dialog for this, e.g.:

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();
            }
        });
    }
}
巴黎夜雨 2025-01-05 03:52:18

builder.setCursor(cursorCall, 监听器,
android.provider.CallLog.Calls.CACHED_NAME);

更改为

 builder.setCursor(cursorCall, listener,
                    android.provider.CallLog.Calls.NUMBER);

未知数字未显示..代码工作 100%,谢谢

builder.setCursor(cursorCall, listener,
android.provider.CallLog.Calls.CACHED_NAME);

Changed to

 builder.setCursor(cursorCall, listener,
                    android.provider.CallLog.Calls.NUMBER);

as unknown numbers were not showing..the code is Working 100% , Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文