我是一个正在使用他的第一个应用程序的菜鸟。假设您很忙,白天无法接听一些电话。该应用程序会向您显示未接来电的日志,您只需单击一下按钮即可开始拨打电话。并非一次全部-您从第一个未接号码开始,在通话结束后自动返回到应用程序,自动拨打第二个号码,依此类推,直到列表为空或完成通话为止。这是我现在的应用程序外观:

https://imgur.com/tke7SDx

我记录未接来电并显示它们,我有一个“开始通话”按钮,应该可以开始循环。我不确定如何做到这一点,以便onClick开始呼叫未接电话1,然后再呼叫未接电话2等,尽管我的Google游戏还不是很强大,但我对它并没有太多了解。这是我如何获得通话详细信息:

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();
            }
        }
    });


我也正在尝试对其进行过滤,以便仅显示过去两天的未接来电,但这是以后的事情。只是想知道现在有什么方法可以使未接来电循环通话。

任何指针都欢迎!!

谢谢!

最佳答案

您可以使用Phone State Listener监听呼叫状态。每当通话状态返回到STATE_IDLE时,您都可以继续通话。

完成后,别忘了停止监听状态。

09-04 19:28