拨打错过号码的日志?

时间:2017-10-18 07:19:38

标签: java android

我是一个在第一个应用上工作的菜鸟。想象一下,你很忙,白天不能接听电话。该应用程序会显示您错过的呼叫记录,您只需单击一下按钮即可开始呼叫它们。不是一次全部 - 您从第一个错过的号码开始,在呼叫结束时自动返回应用程序,自动拨打第二个号码,依此类推,直到列表为空或您已完成呼叫。这是我的应用程序现在的样子:

https://imgur.com/tke7SDx

我记录未接来电并显示它们,我有一个"开始呼叫"应该启动循环的按钮。我不确定如何制作它以便onClick开始拨打未接来电no1,然后未接来电No2等我虽然我的谷歌游戏还不是很强大,但我还没有发现它。这就是我获取通话详情的方式:

public String getCallDetails() {

    StringBuffer sb = new StringBuffer();

//        if 
// (ActivityCompat.checkSelfPermission(getApplicationContext(), 
// Manifest.permission.READ_CALL_LOG) != 
// PackageManager.PERMISSION_GRANTED) {
//
//            return ;
//        }

    Cursor managedCursor = getApplicationContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " DESC");

    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
    int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
    int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);

    sb.append("\n");

    while (managedCursor.moveToNext()) {
        String phNumber = managedCursor.getString(number);
        String callType = managedCursor.getString(type);
        String callDate = managedCursor.getString(date);
        Date callDayTime = new Date(Long.valueOf(callDate));
        String callDuration = managedCursor.getString(duration);
        String dir = null;
        int dircode = Integer.parseInt(callType);

        switch (dircode) {
            case CallLog.Calls.OUTGOING_TYPE:
                dir = "OUTGOING";
                break;

            case CallLog.Calls.INCOMING_TYPE:
                dir = "INCOMING";
                break;

            case CallLog.Calls.MISSED_TYPE:
                dir = "MISSED";
                break;
        }

        // Getting the current date and time using the date class
        Date d = new Date();

        if (dir == "MISSED") {

            sb.append("\n   Phone Number: " + phNumber + " \n   Call Date: " + callDayTime + "\n");
            sb.append("   ---------------------------------------------------\n \n");

        }
    }

    managedCursor.close();
    return sb.toString();

}

这是我的按钮onClick:

callBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            try {

//                    String phone = ????
// Using the ACTION.CALL intent, you're going straight to the first 
// call                      
//                    Intent callIntent = new 
//                    Intent(Intent.ACTION_CALL, Uri.fromParts("tel", 
//                    phone, null));

                // Check for permission, write yes/no etc. here
                if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CALL_PHONE) !=
                        PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE},
                            UNIQUE_REQUEST_CODE);
                } else {
                    Toast.makeText(MainActivity.this, "Permission granted! Thank you!", Toast.LENGTH_SHORT).show();

                }
                startActivity(Intent.createChooser(callIntent, "callTitle"));

            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "Oh no, your call has failed!",
                        Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    });

我也试图对其进行过滤,以便只显示过去两天的未接来电,但这是以后的事情。只是想知道现在通过未接来电呼叫循环的好方法。

欢迎任何指示!!

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以使用Phone State Listener来收听通话状态。每当通话状态返回STATE_IDLE时,您就可以进行下一次通话。

完成后不要忘记停止列出状态。