Darshan Kharwa
Darshan Kharwa

Reputation: 29

how to make phone call to last dial number on button from my app click

Here's the code that I could work out:

Intent intent = new Intent(Intent.ACTION_CALL);

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

Upvotes: 1

Views: 582

Answers (3)

Kalaji
Kalaji

Reputation: 425

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

and add to the manifest this permission

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

Upvotes: 3

Vipul
Vipul

Reputation: 28093

Here you go.

Include <uses-permission android:name="android.permission.READ_CONTACTS"/> in manifest

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

Upvotes: 0

Ran
Ran

Reputation: 4157

You can use CallLog.Calls.getLastOutgoingCall to get the last outgoing call and then use your intent to call it.

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

Upvotes: 1

Related Questions