I am making android apps we need callerID ,How can proceed it i.e. when any user call from android device we want find out callerID. Thanks.
            Asked
            
        
        
            Active
            
        
            Viewed 2,540 times
        
    1
            
            
        - 
                    I am not sure but just check it out this [link][1] it may help you out [1]: http://stackoverflow.com/a/15564021/2492925 – Amin Kodaganur Oct 19 '13 at 09:52
3 Answers
3
            
            
        You can implement a BroadcastReceiver and deal with telephony events like this:
public class CallListener extends BroadcastReceiver {
private static final String OUTGOING_CALL_ACTION = Intent.ACTION_NEW_OUTGOING_CALL;
private static boolean isOutgoingCall;
private static String savedNumber;
@Override
public void onReceive(Context context, Intent intent) {
    int event = -1;
    String action = intent.getAction();
    if (action.equals(OUTGOING_CALL_ACTION)) {
        // get phone number from bundle
        savedNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        isOutgoingCall = true;
    }
    else
    {
        //gets phone's state
        String phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        if(phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING))
        {
            isOutgoingCall = false;
            //gets the phone number of this incoming call
            savedNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Log.d(TAG, String.format("Received phone call from [%s]", savedNumber));
        }
        else if(phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE))
        {
                // call ended
            Log.i(TAG, TelephonyManager.EXTRA_STATE_IDLE);
            savedNumber = null;
            event = InCallManager.CALL_STATE.EVENT_IDLE;
        }
        else if(phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
        {
                // call answered
            if(isOutgoingCall) {
                event = InCallManager.CALL_STATE.EVENT_OUTCALL;
                isOutgoingCall = false;
            }
            else {
                event = InCallManager.CALL_STATE.EVENT_INCALL;
            }
        }
    }
}
}
in your manifest just add:
<receiver android:name="receivers.CallListener">
      <intent-filter>
          <action android:name="android.intent.action.PHONE_STATE" />
      </intent-filter>
</receiver>
 
    
    
        Inon Stelman
        
- 955
- 7
- 12
0
            
            
        create a broadcast receiver class and use incoming intent....
public class Sms_Res extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        String num=null;
        num=intent.getStringExtra("incoming_number");
        Toast.makeText(context,num, Toast.LENGTH_LONG).show();
    }
}
 
    
    
        Eugene Loy
        
- 12,224
- 8
- 53
- 79
 
    
    
        Akhil S
        
- 1
0
            
            
        You should use a Broad cast receiver as follows:
Register your broadcast receiver in manifest file as follows:
<receiver android:name="MyOwnBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
and next step is to implement it in your code which can be done as follows
   public class MyOwnBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
    final TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
   String INCOMING_NUMBER = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.e("incoming phone number is",""+INCOMING_NUMBER);
    }
    }
 
    
    
        Karan_Rana
        
- 2,813
- 2
- 26
- 35
