1

call.java:

   public class Call extends Activity{
boolean timerhasstarted;
Intent callIntent;
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        call();
    }
    void  call()
    {
        String num="7829893070";
     callIntent=new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:"+num));
        if(!timerhasstarted)
        {
        startActivity(callIntent);
        ct.start();
        timerhasstarted=true;
        }
        else {
            ct.cancel();
            timerhasstarted=false;
            Toast.makeText(getApplicationContext(), "timer not started ",Toast.LENGTH_SHORT ).show();
        }
       }
   CountDownTimer ct=new CountDownTimer(10000,1000) {
    @Override
    public void onTick(long millisUntilFinished) {
        Toast.makeText(getApplicationContext(), "time: "+millisUntilFinished/1000, Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onFinish() {
        Toast.makeText(getApplicationContext(), "time over ..",Toast.LENGTH_SHORT ).show();
        OutgoingCallReceiver out=new OutgoingCallReceiver();
        out.onReceive(getApplicationContext(),callIntent);
    }
     };
      }

OutgoingCallReceiver.java :

 public class OutgoingCallReceiver extends BroadcastReceiver { 

     public static final String ABORT_PHONE_NUMBER = "7204230210";

     private static final String OUTGOING_CALL_ACTION = "android.intent.action.NEW_OUTGOING_CALL";
     private static final String INTENT_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
     String TAG="EMERGENCY";
     @Override
    public void onReceive(final Context context, final Intent intent) {
    Log.v(TAG, "OutgoingCallReceiver .. : onReceive");
    Log.i( "l", "onReceive()" );
    Log.i( "l", "context: " + context );
    Log.i( "l", "intent: " + intent ); 
    String getphoneNumber = this.getResultData();
    Log.i(TAG,"getphnum "+getphoneNumber);

     String phoneNumber1 = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
     Log.i(TAG,"PHONE_NUMBER  "+phoneNumber1);
    Toast.makeText(context, "PHONE_NUMBER  "+phoneNumber1, Toast.LENGTH_LONG).show();
    if (intent.getAction().equals(OutgoingCallReceiver.OUTGOING_CALL_ACTION)) {
    Log.v(TAG, "OutgoingCallReceiver NEW_OUTGOING_CALL received");
     Toast.makeText(context, "OutgoingCallReceiver NEW_OUTGOING_CALL received", Toast.LENGTH_SHORT).show();  

        // get phone number from bundle
       String phoneNumber = intent.getExtras().getString("android.intent.action.NEW_OUTGOING_CALL");
        if ((phoneNumber != null) && phoneNumber.equals(OutgoingCallReceiver.ABORT_PHONE_NUMBER)) {
            Toast.makeText(context, "NEW_OUTGOING_CALL intercepted to number 123-123-1234 - aborting call",
                Toast.LENGTH_LONG).show();
            abortBroadcast();
           // this.setResultData(ABORT_PHONE_NUMBER);
        }
    }
}

phone number

  • String phoneNumber = intent.getExtras().getString("android.intent.action.NEW_OUTGOING_CALL"); //getting null number
  • String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); //getting null number

  • here of both which statement is write to get phonenumber?

  • want to get the outgoing phone number ,but in logcat and in my phone i checked, it is showing null value. why?

  • what statement that i have to write to hold the outgoing caall phonenum?(single call only i have placed).

setResultData(null)

  • with this method, have to end the call,but not ending the call..in my phone? what i have to do to end call in my phone?

logcat

 03-15 11:50:06.062: V/EMERGENCY(490): OutgoingCallReceiver .. : onReceive
 03-15 11:50:06.082: I/l(490): onReceive()
 03-15 11:50:06.082: I/l(490): context: android.app.Application@44f3f8b0
 03-15 11:50:06.082: I/l(490): intent: Intent { act=android.intent.action.CALL dat=tel:7829893070 }
03-15 11:50:06.113: I/EMERGENCY(490): getphnum null
03-15 11:50:06.122: I/EMERGENCY(490): PHONE_NUMBER  null
03-15 11:50:10.522: D/dalvikvm(264): GC_EXPLICIT freed 71 objects / 3424 bytes in 189ms
03-15 11:50:15.653: D/dalvikvm(166): GC_EXPLICIT freed 4298 objects / 244840 bytes in 218ms

here getphnum & PHONE_NUMBER shows null. by toast also i an knowing null in phone device also.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Satya
  • 340
  • 7
  • 17

1 Answers1

1

you can try this for activity then after do this for background service

public void outgoingRecord() 
  { 
          Cursor c = getContentResolver().query( 
              android.provider.CallLog.Calls.CONTENT_URI, 
              null, 
              null, 
              null, 
              android.provider.CallLog.Calls.DATE+ " DESC"); 
          startManagingCursor(c); 
  int numberColumn = c.getColumnIndex( 
          android.provider.CallLog.Calls.NUMBER); 
int dateColumn = c.getColumnIndex( 
          android.provider.CallLog.Calls.DATE); 
// type can be: Incoming, Outgoing or Missed 
int typeColumn = c.getColumnIndex( 
          android.provider.CallLog.Calls.TYPE); 
int durationColumn=c.getColumnIndex( 
        android.provider.CallLog.Calls.DURATION); 
// Will hold the calls, available to the cursor 
ArrayList<String> callList = new ArrayList<String>(); 
try{ 
boolean moveToFirst=c.moveToFirst(); 
Log.e("MOVETOFIRST", "moveToFirst="+moveToFirst); 
} 

catch(Exception e) 
{ 
          Log.e("MOVETOFIRSTERROR","MOVETOFIRST Error="+e.toString()); 
} 

         String callerPhoneNumber = c.getString(numberColumn); 
         int callDate = c.getInt(dateColumn); 
         int callType = c.getInt(typeColumn); 
         int duration=c.getInt(durationColumn); 
         Log.d("CALLS", "callDate="+callDate); 
             switch(callType){ 
              case android.provider.CallLog.Calls.INCOMING_TYPE: 
                          Log.d("INCOMINGCALLLOG", "CallerPhoneNum="+ 
callerPhoneNumber+" "+"Duration="+duration); 
                                break; 
              case android.provider.CallLog.Calls.MISSED_TYPE: 
                                  break; 
              case android.provider.CallLog.Calls.OUTGOING_TYPE: 
                             Log.d("OUTGOINGCALLLOG", 
"CallerPhoneNum="+ callerPhoneNumber+" "+"Duration="+duration); 
                                 break; 
} 

  } 
Google
  • 2,183
  • 3
  • 27
  • 48
  • thank you, from u r code i can get the phone number by taking from call Log.its fine. and also i want to end the call. setResultData(null) is not working... – Satya Mar 15 '12 at 07:27
  • ya kumar i check this code and its not working.but you want to get outgoing number so u recive that using this code so what is the prob? – Google Mar 15 '12 at 08:37
  • k, but what my intesion is to make a call and wait for some time,( i used timer) and has to end call after timer over. please i want code for ending call. – Satya Mar 15 '12 at 09:25
  • hey kumar sorry i haven't this typew of code so sorry.and i can done but i have to take more time so – Google Mar 15 '12 at 09:37