2015-11-10 58 views

回答

0

使用此代碼

public class PhListener extends BroadcastReceiver { 

@Override 
public void onReceive(Context c, Intent i) { 
    // TODO Auto-generated method stub 
    Bundle bundle = i.getExtras(); 

    if (bundle == null) 
     return; 

    String s = bundle.getString(TelephonyManager.EXTRA_STATE); 

    if (i.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { 
     String number = i.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 

    }else if (s.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 
     String number = bundle.getString("incoming_number"); 

    }else if (s.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { 

    }else if (s.equals(TelephonyManager.EXTRA_STATE_IDLE)) { 

    } 

} 

而且在艙單申報

<receiver android:name="com.android.receiver.PhListener" > 
     <intent-filter android:priority="-1" > 
      <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
      <action android:name="android.intent.action.PHONE_STATE" /> 
     </intent-filter> 
    </receiver>