I am not getting the outgoing call phone number? both in emulator and real phone also getting null

懵懂的女人 提交于 2019-12-12 10:15:43

问题


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.


回答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; 
} 

  } 


来源:https://stackoverflow.com/questions/9714989/i-am-not-getting-the-outgoing-call-phone-number-both-in-emulator-and-real-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!