Urgent help on retrieving Outgoing Number

Put your problem here if it does not fit any of the other categories.

Urgent help on retrieving Outgoing Number

Postby hasitharandika » Sun May 02, 2010 11:17 am

hi guys,

i found a method which will return the outgoing number. but
found a issue about the method which finds out the Outgoing
Number. the issue is assume that i have dialed 12345 first. the method
returns the number accurately. but if i dialed 456789 after that
again the method returns the number as 12345.

and if i dialed another number for the third time then the method will
return 456789 as the number.

to have a clear view below is my code.

this is a very urgent case your quick response is really appriciated.

Code: Select all

package com.sabretch.mobility.coloreyed.callerview1.listener;

import java.text.BreakIterator;

import com.sabretch.mobility.coloreyed.callerview1.AnimationView;
import com.sabretch.mobility.coloreyed.callerview1.outgoing.OutGoing;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.provider.CallLog;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallListener extends BroadcastReceiver {
        private Context context;
        // Intent intentttt = null;
        String phonenbr;

        public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
                this.context = context;
                TelephonyManager telManager = (TelephonyManager) context
                telManager.listen(new StateListener(),


        class StateListener extends PhoneStateListener {
                public void onCallStateChanged(int state, String incomingNumber) {
                        // TODO Auto-generated method stub
                        // super.onCallStateChanged(state, incomingNumber);
                        switch (state) {
                        case TelephonyManager.CALL_STATE_RINGING:
                                Log.d("DEBUG", "RINGING");
                        case TelephonyManager.CALL_STATE_IDLE:
                        case TelephonyManager.CALL_STATE_OFFHOOK:
                                phonenbr = getLastCallLogEntry(context);

        private String getLastCallLogEntry(Context context) {
                String[] projection = new String[] { BaseColumns._ID,
                                CallLog.Calls.NUMBER, CallLog.Calls.TYPE };
                ContentResolver resolver = context.getContentResolver();
                Cursor cur = resolver.query(CallLog.Calls.CONTENT_URI, projection,
                                null, null, CallLog.Calls.DEFAULT_SORT_ORDER);
                int numberColumn = cur.getColumnIndex(CallLog.Calls.NUMBER);
                int typeColumn = cur.getColumnIndex(CallLog.Calls.TYPE);

                if (!cur.moveToNext()) {
                        return "";
                String number = cur.getString(numberColumn);
                String type = cur.getString(typeColumn);
                String dir = null;
                try {
                        int dircode = Integer.parseInt(type);
                        switch (dircode) {
                        case CallLog.Calls.OUTGOING_TYPE:
                                dir = "OUTGOING";

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

                        case CallLog.Calls.MISSED_TYPE:
                                dir = "MISSED";
                } catch (NumberFormatException ex) {
                if (dir == null)
                        dir = "Unknown, code: " + type;
                return number;



Posts: 45
Joined: Mon Feb 15, 2010 8:37 am
Location: Sri Lanka


Return to Other Coding-Problems

Who is online

Users browsing this forum: Alexa [Bot], MSNbot Media and 17 guests