如何通过我的应用程序点击拨打按钮上的最后一个拨号号码

时间:2012-06-13 13:00:11

标签: java android

以下是我可以解决的代码:

Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);

3 个答案:

答案 0 :(得分:3)

String uri = "tel:" + CallLog.Calls.getLastOutgoingCall(getApplicationContext()).trim();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);

并向清单添加此权限

<uses-permission android:name="android.permission.READ_CALL_LOG" />

答案 1 :(得分:1)

您可以使用CallLog.Calls.getLastOutgoingCall获取最后一个拨出电话,然后使用您的意图来调用它。

http://developer.android.com/reference/android/provider/CallLog.Calls.html#getLastOutgoingCall(android.content.Context

答案 2 :(得分:0)

你走了。

在清单

中加入<uses-permission android:name="android.permission.READ_CONTACTS"/>
        String lastNumber = "";

        Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
                null, null, null);
        int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
        int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);

        while (managedCursor.moveToNext()) {
            String phNumber = managedCursor.getString(number);
            String callType = managedCursor.getString(type);

            int dircode = Integer.parseInt(callType);
            switch (dircode) {
            case CallLog.Calls.OUTGOING_TYPE:
                lastNumber = phNumber;
                break;
            }
            if (lastNumber.length() != 0)
                break;
        }

            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:" + lastNumber));
            context.startActivity(intent);