2012-03-20 88 views
0

我有一個應用程序撥打特定電話號碼的電話號碼,如果號碼沒有響應應用程序做出行動,我的問題是:我如何知道是否有響應或不響應?!如何檢查是否有響應

這裏是我的代碼:

PhoneCallListener phoneListener = new PhoneCallListener();  
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); 

    telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE); 



    Button emr = (Button) findViewById (R.id.emergButton); 
    emr.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Model m = new Model() ; 
      num=m.getAdminPhone(); 
      String Numb = "tel:"+num; 
       Intent callIntent = new Intent(Intent.ACTION_CALL); 
       callIntent.setData(Uri.parse(Numb)); 
       startActivity(callIntent); 

      if() // here i want to making a check... 
      {answer = true;} 



     } 
    }); 

回答

0

This answer應該有所幫助。

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); 

private PhoneStateListener mPhoneListener = new PhoneStateListener() { 

    public void onCallStateChanged(int state, String incomingNumber) { 
     try { 
      if (state == TelephonyManager.CALL_STATE_OFFHOOK){ 
       // Call wasn't answered 
      } 
     } catch (RemoteException e) {} 
    } 
}; 
0

似乎沒有辦法從撥號器得到結果。 This topic可能會幫助你意識到這一點。所以,使用@Cameron方法似乎更好。

填寫答案接受另一個答案不是很有趣嗎? ;)

相關問題